Hibernate version:
3.1.1
Mapping documents:
Annotations
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
MySQL 5.0.18
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A
I am looking for a pattern/best practice for my application, which I'm sure is fairly common.
I have a number of entities (Person, Location, Customer) that have a set of Contacts. I currently have a one-to-many relationship (Cascade.ALL) from the parent to the Contact with a join table (lazy load). While I perhaps shouldn't know/care about the application, the application deals with the parent entities on different screens than the contact. Thus, when loading the parent object, we don't really need to load all of the contacts (thus, lazy load).
However, when I add a new contact, I need to load the parent from the database (parent's can be huge) and then add the new contact to the list. This is fine. However, when I am just updating the parent entity, I need to also force a load of the child contacts before calling update or all of my contacts "disappear" (I assume because of the Cascade.ALL).
Is this the correct way to model this and correct way to perform the child Contact object updates and inserts?
TIA,
Jim
|