Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How hibernate retrieve data from existing database view?

Tags:

java

hibernate

I'm new to hibernate. My problem is that I have an Oracle database. I have a view in the database. Now I want to use hibernate to retrieve data in that view. Is there any possible solutions?

like image 287
nathan Avatar asked Jan 13 '11 02:01

nathan


People also ask

How does Hibernate connect to database?

It represents the classname of a custom ConnectionProvider which provides JDBC connections to Hibernate. It is used to set the JDBC transaction isolation level. It enables auto-commit for JDBC pooled connections.

How Hibernate get all data?

JPQL provides a simple and straightforward way to get all entities from a table. Our Hibernate session's createQuery() method receives a typed query string as the first argument and the entity's type as the second. We execute the query with a call to the getResultList() method which returns the results as a typed List.

Can we use view in Hibernate?

Hibernate can treat views like it does any table. Just define an entity class based on that view ( Baselines , as you say). The most common difficulty with views is that some database engines can't handle inserts or updates on views, so be aware of that if your application tries to modify the data.


1 Answers

we can achieve this by using @ Immutable annotation in entity class to map database view with Hibernate

For example : I have created one database view user_data which have 2 columns (id and name) and mapped user_data view in the same way as database tables.

@Entity
@Table(name = "user_data")
@Immutable
public class UserView {

    @Id
    @Column(name = "ID")
    private int ID ;

    @Column(name = "NAME")
    private String name ; 
}
like image 70
Om Prakash Sharma Avatar answered Oct 23 '22 13:10

Om Prakash Sharma