Results 1 to 3 of 3

Thread: @Transactional doesn't work

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Default @Transactional doesn't work

    Dao:
    Code:
    @Repository  
    public class UserDaoImpl implements UserDao {   
        @Autowired  
        private HibernateTemplate tmp;   
      
        public void addUser(Users u) {   
            tmp.save(u);   
        }   
    }
    Service:
    Code:
    @Service  
    @Transactional  
    public class UserServiceImpl implements UserService {   
        @Autowired  
        private UserDao userDao;   
           
        public void addUser(Users u) {   
            this.userDao.addUser(u);   
            //throw an exception to test whether the transaction will rollback.   
            throw new RuntimeException("Exception occurred in UserService...");   
        }   
    }
    XML configuration
    Code:
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory" />  
    </bean>  
    <tx:annotation-driven transaction-manager="transactionManager" />  
    <context:component-scan base-package="com.spring" />
    in the service,i throw an exception to test whether the transaction will rollback, however,the transaction didn't rollback.
    So who can tell me why? thanks very muck!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    How are you testing this?

    If you use MySQL make sure you use InnoDB tables and not MyISAM tables the latter doesn't support transactions.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2009
    Posts
    2

    Default

    Quote Originally Posted by Marten Deinum View Post
    How are you testing this?

    If you use MySQL make sure you use InnoDB tables and not MyISAM tables the latter doesn't support transactions.
    Thank you,there is something wrong in the XML configuration.
    The <tx:...> and <Context:...> should be in the xxx-servlet.xml,not the applicationContext.xml.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •