我不熟悉hibernate,concurrrency问题和陈旧的异常。
我在高并发环境中使用GORM处理grails。乐观锁定打开,我在事务服务中使用静态锁定方法。
for(Entity entity : entityList) {
//refresh and lock for update
entity.refresh();
entity = Entity.lock(entity.id)
entity.setSomeData(new Date());
entity.save()
}
在这种情况下,以某种方式可能会出现HibernateOptimisticLockingFailureException吗?
请注意堆栈跟踪:
Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.xxxxx.xxx.xxxxx.Entity#48225]
at org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy.lock(PessimisticWriteSelectLockingStrategy.java:94)
at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1954)
at org.hibernate.event.internal.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:102)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSessionCache(DefaultLoadEventListener.java:560)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:430)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)
at org.hibernate.event.internal.DefaultLoadEventListener.lockAndLoad(DefaultLoadEventListener.java:391)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:153)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)
at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2544)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:1023)
at org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate$5.doInHibernate(GrailsHibernateTemplate.java:282)
at org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:179)
at org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate.lock(GrailsHibernateTemplate.java:279)
at org.codehaus.groovy.grails.orm.hibernate.HibernateGormStaticApi.lock(HibernateGormStaticApi.groovy:221)
at com.xxxxx.xxx.xxxxx.Entity.lock(Entity.groovy)
静态Entity.lock()如何抛出过时的对象异常?