I have the same issue as below, and seem no one provided an answer, I have the exact same situation. Basically, even i hardcod the setting of the version number to the object it seems that hibernate reads from the DB and i can see the call to <engine.Versioning.increment from value(read from DB to new incremeneted value)>
Any idea?
Thanks,
Hadi
Hibernate version: 2.1.2
We are using the "Many sessions with automatic versioning" approach on our application (section 17.3.2.).
We have a brand new Hibernate Session for each service layer request and we use DTOs to communicate across the service boundary (ie. the client never sees the domain objects).
I think I have seriously misunderstood what we could do with this functionality, but I'd like to double-check that I'm not simply doing something wrong.
Versioning is working fine, and I believe that ordinary optimistic locking is working fine.
The problem is, I want to override the version number on a particular instance (setting it to a specific, possibly older number) and have hibernate detect (by issuing the update statement with the given version number in the where clause) if the version of the object is stale.
I wanted to do this: Domain domain = session.load(Domain.class, dto.getId());
domain.setSomeValue( dto.getSomeValue() );
domain.setVersion( dto.getVersion() );
session.commit();
And have hibernate throw an exception during the commit call if the version number in the DB had moved on from the version number I set.
According to my debugger, the part where I call domain.setVersion() works fine. But inside the call to session.commit(), the domain.version attribute just gets set to whatever the version in the DB is (regardless of how far in advance it is to the number my code set in the version attribute) + 1.
So, hibernate appears not to look at the version I set onto the domain object, it just overwrites it, yes?
I know I can do my own version checking in application code, I just was under the impression that hibernate would do that for me.
So, I guess the question is: hibernate won't do the version check for me if I override the version number on the domain object, will it?
_________________
Cheers,
Shorn.
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|