Hello!
One can statically determine if a save in one entity leads to a save in an associated entitie (or entities, for many-case) by means of the cascade-attribute in the mapping or by annotations.
But is it also possible to determine the desired behaviour for the following cases?
1. For value-objects, then of course dynamically, other would make no sense.
2. For associations, also dynamically? So for example if I have a one-to-many relationship owned by the one side in order to manage the order of entries.
My question has the following background.
I think about to make different DAO-Methods that accept the same Classtype as parameter but save or update different parts of an Entity.
The desired behaviour would optimize the performance especially when the associated objects are not in the hibernate-cache, as it might probably the case in web applications and a session-per-request style.
I´ve just found out, that for associations ONE-TO-MANY OR MANY-TO-MANY Hibernate itsself determines if the Collection of associated Entities has changed. This
can be achieved because Hibernate has it´s own Collection implementation and can determine if the Collection has changed since it has been initialized.
So the performance arguement is not given anymore.
But still I want to have my "complex" DAO-Layer, because I want to be able to change to an other persistence mechanism that is not that intelligent.
But the problem is, if I write a DAO-Method that shall only save parts of the Entity and the associations it manages, I have to be sure that nothing else
is saved, also if something has changed.
I hope somebody understands my question. :-)
Thank you very much in advance.
Jörg
|