Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Basically, the first update should win and the second should fail.</p> <p>Does it suffice to add a version to the Member class</p> </blockquote> <p>Yes, it does. Say you and I read an entity from the database with version = x. I make some changes to property1 of the entity and commit to the database. Now the entity in the database has version = x+1. Now, you change property2 of your version of the entity (property1 still holds the older value). When you update the changed entity to the database, the changes made by me to property1 would be lost as you would overwrite it with the old value. But this will not happen as Hibernate would check from any changes that might have occurred between the time of reading the entity and updating it. When you go to update the entity Hibernate sees that the version of the entity in the database is different from the version of entity that you have provided. This means that someone else has made some changes to the object i.e. the object that you have supplied is stale and hence a StaleStateException is thrown.</p> <blockquote> <p>However, say that there is a gender field, I would like to be able to update the gender field without caring if the location is being updated by another transaction.</p> </blockquote> <p>This is not possible using hibernate (it should be clear from the above example). If this was supported, then changes made to the location would be lost when and update made to the gender is committed containing the older value of location. Some degree of tolerance can be achieved using some logic and explicit version checking and updating the changed fields before updating the entity, but the problem still exists, you can never know at what moment the changes will be made to the object. In my opinion, such an implementation will be an overkill with not enough benefit.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload