This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate many-to-one problem

 
Kimbo Inatl
Greenhorn
Posts: 14
  • 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: 14
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic