wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate many-to-one problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate many-to-one problem" Watch "Hibernate many-to-one problem" New topic

Hibernate many-to-one problem

Kimbo Inatl

Joined: Jun 30, 2010
Posts: 11
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

Joined: Jun 30, 2010
Posts: 11
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Hibernate many-to-one problem
Similar Threads
Hibernate POJOs -- association or no-association ?
updating association table
Cascade delete to the parent association
Hibernate Association
Hibernate problem: One-To-Many association