• 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 ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Hibernate many-to-one problem  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!