aspose file tools*
The moose likes Object Relational Mapping and the fly likes need good example of hibernate with composit key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "need good example of hibernate with composit key" Watch "need good example of hibernate with composit key" New topic
Author

need good example of hibernate with composit key

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

may i know a good example of hibernet with composit key and the code.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Here's a little tutorial I put together on the topic of Hibernate JPA and Compound Primary Keys:

Hibernate Composite Key Mapping Example



The tutorial shows several ways to do it.








-Cameron McKenzie







Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

does Hibernate fully supports composite key? or we should look of some other technology? or simply use JDBC?
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Good to see your post, is using JPA is a must to implement Composite key or else we can also do it with simple Hibernate?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

I like JPA annotations. There is an equivalent entry in a Hibernate mapping file, if you please.
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Cameron Wallace McKenzie wrote:I like JPA annotations. There is an equivalent entry in a Hibernate mapping file, if you please.


but no where it is mentioned in your tutorial as to how to create .hbm.xml file for all java class may i know where can i find it?

thanks in advance,
ra.
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Cameron Wallace McKenzie wrote:I like JPA annotations. There is an equivalent entry in a Hibernate mapping file, if you please.


you used @@Embeddable @Id @Entity, but i do not want to use and implement the annotations and EJB. can you please let me know how to proced with plaing old hibernate(composit-key)?

many thanks in advance,
rahul.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Hello All,

I'm relatively new to Hibernate and ORM world and having absolutely zero knowledge in JPA and annotations. I did some programming in Hibernate for my learning purpose but have not really used composite keys. I'm not sure, if this thread is the right thread for that, but would like to utilize the conversation already started.

1) Is there any alternative way to declare the composite keys using mapping xmls? If so, a small example is appreciated.

2) When we say session.save(object), it returns a serializable object identity. How would this behave, when I have composite keys in the database?


THanks
Kumar


Regards
KumarRaja

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need good example of hibernate with composit key