Hibernate Optimistic castle. Selects a version, even if it generates it

I have an entity:

<class name="name.dargiri.model.Entity" table="ENTITY" optimistic-lock="version">
  <version name="version" column="ver" type="long" />
</class

If Entity is saved no matter how many times, at the end of the transaction, Hibernate selects the version of the object. What for? Hibernate generates this version when it stores an object, so it knows that. I found out that this method calls this:

EntityVerifyVersionProcess#getCurrentVersion()

Sleep mode generates this in the logs:

Hibernate: 
    /* update
        name.dargiri.model.Entity */ update
            ENTITY 
        set
            ver=?,
            USERNAME=?,
            lucky_number=? 
        where
            id=? 
            and ver=?
Hibernate: 
    /* get version name.dargiri.model.Entity */ select
        ver 
    from
        ENTITY 
    where
        id =?

I am using MySQL and Session # save ().

+3
source share
2 answers

Well, therefore, what I did not write about, and which apparently was the problem, is using LockMode.OPTIMISTIC: session.get(Entity.class, 1L, LockMode.OPTIMISTIC);

, - , . , Hibernate , , , , , .

0

Hibernate SQL , , . .

0

All Articles