Hibernate version: 2.15 or so
Hello,
I have a 'best practises' question.
I have a 'root' entity/table called User. Almost all other entities/tables are associated with this User entity via FKs.
e.g.
User <-- FK -- UserProfiles
User <-- FK -- UserMessages
User <-- FK -- UserDemographics
User <-- FK -- UserPreferences
...
I guess this would be the Parent/Child relationship from HIA and online docs.
I am wondering about the best way to deal with cascades and entity saveOrUpdate calls.
More precisely, I am wondering whether it is considered best practise to have a DAO layer and saveOrUpdate calls for each of the Child entities, or whether it is better to just make proper bidirectional associations between Parent/Child entities, along with cascade="all-delete-orphan" and then just always call saveOrUpdate(Parent), and rely on Hibernate doing all transitive persistence, dirty checking, and doing all inserts, updates and deletes based on the cascade setting?
I am just worried about always going through this Parent entity. It would make code simpler - there would be no need to DAO layer save/update/delete for individual Child entities, but are there any dangers associated (no pun intended, really) with this?
In my case the Parent has a few Bags (List collections) associated with it, and some of those collections can have several thousand entities in them.
I guess my primary worry is how efficient and reliable it is to let Hibernate iterate through such collections on every XA commit in order to find dirty objects in associated collections, as opposed to me manually calling save/update/delete on those entities when the application calls for that.
Thanks,
Otis
|