We use spring and hibernate in standalone application and have problems with HibernateException propagation to DAO. The problem is very enigmatic because propagation works for all methods except delete. When service method uses DAO.delete() in specific situation we get following exception:
org.springframework.orm.hibernate.HibernateOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for net.lidotech.biceps.domain.RecoveryProcedure instance with identifier: 35; nested exception is net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for net.lidotech.biceps.domain.RecoveryProcedure instance with identifier: 35
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for net.lidotech.biceps.domain.RecoveryProcedure instance with identifier: 35
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:501)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:594)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2365)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:339)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:302)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:174)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:196)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:135)
at $Proxy70.removeRecoveryProcedure(Unknown Source)
...
Service method uses suitable DAO to remove object from persistent layer:
Unfortunately this method does not enter catch() block despite HibernateException is thrown. Why?? It works properely with all other methods in this DAO.
Spring configuration for this service looks as following:
ServiceException is our exception - HibernateException is translated firstly in DAO into Dao*Exception and subsequently into ServiceException in service method.
I would thank for all help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That exception happens during flushing on commit, i.e. right after the target operation has finished. Just the caller will be able to catch that exception, which will be rethrown by HibernateTransactionManager as Spring DataAccessException (like Spring's HibernateTemplate does).
This is normal Hibernate behavior, actually: Operations like saveOrUpdate and delete just register changes, to be flushed at commit time. You can cause eager flushing through explicit flush calls on the Hibernate Session, if you want: The exception will then occur within the DAO itself.
Juergen
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-07-09
thanks for your quick response - now it works
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi there,
We use spring and hibernate in standalone application and have problems with HibernateException propagation to DAO. The problem is very enigmatic because propagation works for all methods except delete. When service method uses DAO.delete() in specific situation we get following exception:
org.springframework.orm.hibernate.HibernateOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for net.lidotech.biceps.domain.RecoveryProcedure instance with identifier: 35; nested exception is net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for net.lidotech.biceps.domain.RecoveryProcedure instance with identifier: 35
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for net.lidotech.biceps.domain.RecoveryProcedure instance with identifier: 35
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:501)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:594)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2365)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:339)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:302)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:174)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:196)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:135)
at $Proxy70.removeRecoveryProcedure(Unknown Source)
...
Service method uses suitable DAO to remove object from persistent layer:
recoveryProcedureDao_.delete(procedure);
DAO delete method looks like this:
public void delete(Object o) throws DaoException {
updateSession();
try {
session_.delete(o);
} catch (HibernateException ex) {
throw DaoExceptionUtils.translate(daoClassName_, ex);
}
}
Unfortunately this method does not enter catch() block despite HibernateException is thrown. Why?? It works properely with all other methods in this DAO.
Spring configuration for this service looks as following:
<bean id="BCPSRecoveryService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="BCPSTransactionManager"/>
</property>
<property name="target">
<ref bean="BCPSRecoveryServiceTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="remove*">PROPAGATION_REQUIRED,-ServiceException</prop>
<prop key="retrieve*">PROPAGATION_REQUIRED,-ServiceException</prop>
<prop key="store*">PROPAGATION_REQUIRED,-ServiceException</prop>
<prop key="init*">PROPAGATION_REQUIRED,-ServiceException</prop>
</props>
</property>
</bean>
ServiceException is our exception - HibernateException is translated firstly in DAO into Dao*Exception and subsequently into ServiceException in service method.
I would thank for all help.
That exception happens during flushing on commit, i.e. right after the target operation has finished. Just the caller will be able to catch that exception, which will be rethrown by HibernateTransactionManager as Spring DataAccessException (like Spring's HibernateTemplate does).
This is normal Hibernate behavior, actually: Operations like saveOrUpdate and delete just register changes, to be flushed at commit time. You can cause eager flushing through explicit flush calls on the Hibernate Session, if you want: The exception will then occur within the DAO itself.
Juergen
thanks for your quick response - now it works