Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

composite key in annotations

 
rudresh kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i have implemented the composite key in hbm file, which is as below (child.hbm)

<composite-id>
<key-many-to-one name="master" class="com.bo.master" column="MASTER_ID" ></key-many-to-one>
<key-property name="child" type="java.lang.Integer" column="CHILD_ID"></key-property>
</composite-id>

This works fine, but i would like to convert this into a annotations and remove the hbm files. Can i know how the definition would be for the annotations on the child class (com.bo.child) for composite key.

Thanks

 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a "Team has many Players" example on Hibernate Tutorials Website that shows the basics of a one to many or many to one relationship mapped in Hibernate with JPA annotations:










That demonstrates a simple relationship. Just apply the corresponding Team and Player values to your scenario, and you'll have it mapped!

Example of Mapping One To Many Associations with Hibernate and JPA Annotations

-Cameron McKenzie

 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!