• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate many-to-one problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a many-to-one relationship in Hibernate - Facility and Contact. A facility can have multiple contacts (each Facility has a set of Contacts). The association is uni-directional.

I am creating a Facility, then creating a Contact and adding that to the Facility's Contact Set. Then I'm saving Facility using session.save(). I've written my HBM file like this so that it will save all the Contacts when I save the Facility (or delete them all if I delete the Facility):



But when I save it, it's not saving the association - in other words, it's not setting the FACILITY_ID in the CONTACT. I don't have a FACILITY_ID yet because it's generated when I save Facility. Is there an easy way to tell Hibernate to set the FACILITY_ID in CONTACT? I guess I could save it, and then get the FACILITY_ID, and then set that manually in each Contact that got saved and update them, but it seems like there should be a better way.

 
Kimbo Inatl
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind. I must have been pretty tired when I posted this last night - the answer was pretty obvious. Admin, you can delete this thread if you want.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic