• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate composite key with foregin key to another table - How to avoid circular reference?

 
Rav Nomula
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Student table with an auto generated id as primary key and one to many mapping to Phone table.

My Phone table has a composite key PhonePK with phone number and the foreign key id to the Student table as primary keys.

If I do phonePk.setStudent it works but I really don't want to do this. How can I achieve this? If its not achievable, I would like to settle with setting the student id but not the whole student object. How do I do this? Would really appreciate if someone can give an insight on this.

Student.java



Phone.java


PhonePK.java



Main.java


hibernate.cfg.xml

 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
 
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!