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

Basic question on composite id.

 
Arjun Abhishek
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 entity classes as below.

1. Student
private int id // This is the PK for this table
// In the mapping i am using the generated id
2. Course
private int id // This is the PK for this table
// In the mapping i am using the generated id
3. Result
private Student student
private Course course
private int uniqueNumber // All the 3 field are to be part of the composite id.

What should be the mapping in the result.hbm.xml

thanks
Arjun.
 
Reehan Lalkhanwar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Something like this.
 
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
Just as a helpful tip, if you have some complex mappings, The Hibernate Tools download provides some great Eclipse plugins that will automatically generate mappings for complex relationships and complex surrogate and composite keys.

-Cameron McKenzie
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!