Announcement Announcement Module
Collapse
No announcement yet.
Problem with transactionManager. The rollback does not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with transactionManager. The rollback does not work

    Hi guys

    I have a problem with transactionManager. The rollback does not work. I'm using Spring 3.0.6 and Hibernate 3.9.0

    My settings


    context.xml
    Code:
    		<context:annotation-config/>
    		<context:component-scan base-package="project.cmi"/>
    		<tx:annotation-driven transaction-manager="txManager"/>
    
    		<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    			<property name="locations" value="classpath:project/cmi/jdbc.properties"/>
    		</bean>
    
    		<bean id="cmiDS" 
    			  class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
    			<property name="driverClassName" value="${jdbc.driverClassName}"/>
    			<property name="url" value="${jdbc.url}"/>
    			<property name="username" value="${jdbc.username}"/>
    			<property name="password" value="${jdbc.password}"/>						
    		</bean>
    
    		<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    			<property name="dataSource" ref="cmiDS"/>
    		</bean>
    
    		<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">		
    			<property name="dataSource" ref="cmiDS"/>
    			<property name="packagesToScan" value="project.cmi.domain"/>			
    			<property name="hibernateProperties">
    				<value>
    					hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
    					hibernate.show_sql=true
    					hibernate.format_sql=true
    				</value>
    			</property>		
    		</bean>
    Repository
    Code:
    @Repository("contactRepository")
    public class ContactRepository {
    
    	@Autowired	
    	private SessionFactory sessionFactory;	
    		
    	public void persist(Contact contact){
    		sessionFactory.getCurrentSession().save(contact);
    	}
    	
    }
    Service
    Code:
    @Transactional(readOnly=true)
    @Service("contactService")
    public class ContactService {
    
    	@Autowired	
    	private ContactRepository contactRepository;
    		
    	@Transactional(propagation=Propagation.REQUIRED, readOnly=false, rollbackFor={RuntimeException.class})
    	public void persist(Contact contact) throws Exception {
    
    		contatoRepository.persist(contact);
                    throw new RuntimeException;  //The rollback does not work
    		
    	}
    	
    }
    Thank you for help!

  • #2
    I suggest that you first fix your configuration. You are using hibernate but using the wrong transactionamanger. So basically you aren't in control of your transactions. Use the HibenateTransactionManager.

    Comment


    • #3
      Hi Marten

      Thanks for the help. Substitution did, but the problem continues ...

      Code:
      	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      		<property name="sessionFactory" ref="sessionFactory"/>
      	</bean>

      Comment


      • #4
        I suggest a forum search as questions like these have been answered numerous times before. If rollback isn't happening you have either something wrong in your code (like catching exceptions) or you are using a database (or tables) that don't support transactions (like MyISAM tables in MySQL).

        Also rollback is default for runtime exceptions so not sure why you want that included in your rollbackFor configuration.

        Comment


        • #5
          It worked!

          Thank you, was right in the table was MyISAM.
          Changed to InnoDB and it worked perfectly.

          Comment

          Working...
          X