-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: transaction fails after the method returns
PostPosted: Wed Sep 15, 2010 12:19 pm 
Newbie

Joined: Thu Sep 10, 2009 2:43 am
Posts: 7
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)


Top
 Profile  
 
 Post subject: Re: transaction fails after the method returns
PostPosted: Tue Sep 21, 2010 9:43 am 
Newbie

Joined: Thu Sep 10, 2009 2:43 am
Posts: 7
Well, I guess it is obvious... The method is annotated as "SUPPORTS" and not "REQUIRED"...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.