Hibernate versioning
What is offline lock/optimistic concurrency control?
http://developer.mimer.com/features/feature_15.htm
Versioning implemented via <version name="version"/> in customer's hibernate mapping.
using_Version_Column
I load a customer and change email address.
You load the same customer and change email address.
I commit the customer.
You commit the customer.
You get StaleObjectStateException
disconnect_And_Save_With_Old_Version
I load a customer get its version, = X.
You save the customer with new email address.
I load the customer.
I change the customer.
I set the version number = X.
I save the customer.
No StaleObjectStateException is thrown. Offline lock implementation ignores the value version field in your object.
Question: Why do we need the version field in the object, shouldn't it be managed internally by hibernate?
verify_Version_Yourself_For_Disconnect_Locking_Scope
I load a customer get its version, = X.
You save the customer with new email address.
I load the customer.
I change the customer.
I verify X against current customer version.
verifyVersion method throws StaleObjectStateException.
Note: In a graph of objects this approach of verification can be tedious. For example, in this case one would need to verify the version of all accounts, addresses under customer.
no_Change_And_Flush_Doesnt_Change_The_Version
Load a customer.
Flush the session.
The version of customer doesn't change.
no_Change_To_Parent_Doesnt_Update_Its_Version
Load a customer.
Withdraw money from one account (changes the account object).
Save the customer.
Customer's version doesn't change.
new_Child_Changes_The_Parents_Version
Get a customer.
Add a new account.
Save the customer.
The version of customer changes.
save_Or_Update_Without_Change_Doesnt_Change_The_Version
Load a customer.
Save the customer.
The version of customer doesn't change.