Hi all
this is my method:
Code:
@Transactional(propagation = Propagation.SUPPORTS, readOnly=false, rollbackFor = HibernatePersistenceException.class)
public void create(T newInstance) throws PersistenceException
{
try
{
getSession().save(newInstance);
System.out.println("1");
}
catch (Exception e)
{
System.out.println("2"+e);
throw new HibernatePersistenceException("Failed creating.", e);
}
}
Usually this works... But:
In some cases, this method creates the instance, and tries to create another object (connected to it by onetomany). The other object fails - because of a real problem (nevermind what).
This throws me an exception only after the method is done! I see the "1" print! and the stacktrace indeed says:
...
at org.springframework.transaction.interceptor.TransactionAspectSupport.
commitTransactionAfterReturning(TransactionAspectSupport.java:393)
...
However, the root object is created in the DB! the transaction is not rolled back.
How can taht be?
Thanks
Yair
More stack trace...:
Code:
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:642)
at org.springframework.orm.hibernate3.SpringSessionSynchronization.translateException(SpringSessionSynchronization.java:160)
at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:148)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:927)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:737)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy26.create(Unknown Source)