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.
posted 5 years ago
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.