Domanda

I've got a problem setting the lock mode on an object.

Here is the code :

MyObject a = myQuery.getSingleResult();
logger.info(entityManager.getLockMode(a));
entityManager.lock(a, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
logger.info(entityManager.getLockMode(a));

The result is :

OPTIMISTIC
OPTIMISTIC

My object A contains a list of objects B. I would like to increment A whenever a B is modified, here is why I use the Force increment feature.

But obviously it's not working at all. Some help please ?

È stato utile?

Soluzione

So after a lot of searching, I was using Hibernate 3.6.10.Final version which has this superb bug : https://hibernate.atlassian.net/browse/HHH-5222

upgrade from READ to OPTIMISTIC_FORCE_INCREMENT fails

Fix Version/s: 4.0.0.CR7

In short, by default the lock is set to READ which has a higher priority than OPTIMISTIC OR OPTIMISTIC_FORCE_INCREMENT so you can't change it.

So I upgraded to 4.2.0.Final and everything went ok

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top