Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

hibernate 4+ one to many relationship

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).
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic