Hi,
I have been trying out the various update options in Hibernate.
These options are being evaluated for load in one request and update the changed records in the next request.
We are following a session-per-request pattern.
The project requires me to write update statements, updating only the fields which have changed.
As I understand Hibernate provides me with three options
1. Load the object again in the new session and perform an update. This option has an extra select clause associated with it, which I want to avoid.
2. Updating an object which has been loaded in the previous session.
Here I am facing two problems
i. The update statement fires an update on all the columns, even if only one column is changed.
ii. In the case of an one-to-many relationship with cascade enabled, all the child rows get updated when the parent is updated.
This option hence fires too many queries.
3. There is one more option where I can do a session.lock on Lock mode NONE and store the object in the cache in the first session and in the subsequent session I will have to retrieve the object from the cache and apply the changes.
This option works fine. However the decision as to when should the cached object be removed from the session, leads to a huge overhead.
i.e. If the user views the screen and does not press save. There is no way of clearing the session. (My appl. is a rich client app and there is no session timeout feature)
Hence I am constrained in all the features of update.
I need some guidance on the method to be used.
_________________ Manoj Karanth
|