my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes hibernate mapping a view no primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate mapping a view no primary key" Watch "hibernate mapping a view no primary key" New topic
Author

hibernate mapping a view no primary key

andy kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 57
I have a view which comprises of joining 4 table and it does not have a primary keys, this view is just used for display purpose. I want it to be managed by hibernate, I did some search and found that it is not able to have a view mapped to a pojo with out a primary key, one solution is to create a composite key with all the columns in the view and then use @Embeddable annotation, I did this and it worked fine for me. But is there a way to tell hibernate that this POJO is a select only kind of POJO and I will never do a insert/update so no need of a primary key. Or are there any other options that I can try. thanks
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Andy, Did you take a look at "ResultSetTransformers" in Hibernate.
Check for some examples here.


If you are not laughing at yourself, then you just didn't get the joke.
robert walker
Greenhorn

Joined: Sep 05, 2012
Posts: 1
one way to accomplish this is to use constructor expression in your JPQL, so for example, you could do a



in this example, example.EmpMenu class does not have to be an entity, it can be just a pojo, it must have proper constructor to match the constructor expression
in the JPQL.

Nilesh Pat
Ranch Hand

Joined: Mar 01, 2010
Posts: 46
robert walker wrote:one way to accomplish this is to use constructor expression in your JPQL, so for example, you could do a



in this example, example.EmpMenu class does not have to be an entity, it can be just a pojo, it must have proper constructor to match the constructor expression
in the JPQL.



Can you please expalin your logic?


Regards,
Nil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate mapping a view no primary key
 
Similar Threads
simulating select for update in hibernate.
Hibernate: is it necessary to have primary key in table
composite primary keys
Hibernate - Native SQL & result set updates?
hibernate criteria like expression for Long