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

hibernate 4+ one to many relationship

Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in all the tutorial, they use the entire object for one-to-many relationship like so:

but I usually don't use the actual parent object inside child class, just the id of the parent, to mimic the behavior in table. how do I achieve this? so in Detail class, instead of "private Header parentHeader;", I'll just use "private in header_id;" (be careful since both Detail and Header class has "id" field).
Intuitively, I would make something like @OneToMany(fetch = FetchType.LAZY) to annotate the List<Detail> details in Header class and put @JoinColumn(entity = Header.class, colName = "id") in the header_id field in Detail Class. I also need to know how to do this for multiple foreign key (usually for legacy database designs).
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!