Announcement Announcement Module
Collapse
No announcement yet.
Transaction not rolling back with hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction not rolling back with hibernate

    Hi,
    I am trying to roll back a transaction using hibernate transaction manager for a mysql database.

    I have a method in which i insert values into two tables.
    Before inserting into the second table my code throws an exception. But the value from my first table is not roll backed.

    I am using
    Code:
    <bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
    My transaction configuration is:

    Code:
    <tx:advice id="myAdvice" transaction-manager="transactionManager">
    		<tx:attributes>
    			<tx:method name="readAndParse" />
    		</tx:attributes>
    	</tx:advice>
    
    	<aop:config>
    		<aop:pointcut id="myServiceAOP"
    			expression="execution(* com.mime.project.core.module.service.MyCoreService.*(..))" />
    		<aop:advisor advice-ref="myAdvice" pointcut-ref="myServiceAOP" />
    
    	</aop:config>
    My class is :
    Code:
    public void readAndParse(Activity activity)
    	{
    		/*try
    		{*/
    			log.info("in readAndParse()");
    			
    			if(null == activity.geActivityId())
    			{
    				 activityDAO.add(activity);;
    			}
    			save(activity);
    		/*}
    		catch (Exception e)
    		{
    			log.info("Exception in readAndParse...so rolling back..",e);
    		}*/
    
    	}
    Here save(activity) method throws a numberformat exception.
    It shows that it is rolling back a transaction, but it never roll backs.

    Code:
    DEBUG 2012-10-04 18:40:15,076 [pool-19-thread-1] (AbstractPlatformTransactionManager.java:843) (processRollback) - Initiating transaction rollback
    DEBUG 2012-10-04 18:40:15,077 [pool-19-thread-1] (HibernateTransactionManager.java:672) (doRollback) - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@cd429b]
    Where am i going wrong.

    Please help.

    Thanks in advance.
    Regards,

    Annuk
    Last edited by annuk; Oct 4th, 2012, 08:46 AM.

  • #2
    Please use the search as this question has been answered numerous times before...

    You either are using a non-transactional database (MySQL with MyISAM tables) or the first insert is another transaction (REQUIRES_NEW)...

    Comment

    Working...
    X