(Hibernate 2.1.2)
I'm seeking information/advice about the behavior of session.update() and session.saveOrUpdate() with regards to performance.
I understand that if I have a simple object with a handful of properties, as well as an id, and a version number (using a "version" property for optimistic locking) then if I call update() on a session and pass it an instance, the resulting SQL will simply be an UPDATE operation, setting all fields to the values on the object, where the id is the object's id, and the version is the objects version, (and the version # gets incremented). This operation throws an exception if the resulting affected row-count = 0, because either the version # was stale, or the row was deleted.
This is fine and dandy... but what about the following scenario:
I have a large object graph, where the root object contains a one-to-many list of secondary objects, which each contain a one-to-many list of some third objects, and so forth about 6 levels deep. The root object is versioned, and all of the elements down the graph are "owned" by the root (their lifecycle is the root object's lifecycle) - cascading and "delete-all-orphan" is used in the mappings all the way down the tree.
Now, if I create a new session is there any way to reconnect one of these root objects (and its attached graph of objects) and get hibernate to simply notice whether the version number is changed or not, whith out re-writing every row in every table for the entire object graph? (Assuming that *my* code knows for certain that there have been no changes to the object - but I want to attach it to this new session, in preparation to making changes to it).
(I understand that an alternative approach would be to use a long-lived session that I disconnect and reconnect, and always use that session when dealing with this object, but this approach doesn't work for me due to other application needs).
thanks for any pointers...
james
|