Dao:
Service:Code:@Repository public class UserDaoImpl implements UserDao { @Autowired private HibernateTemplate tmp; public void addUser(Users u) { tmp.save(u); } }
XML configurationCode:@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..."); } }
in the service,i throw an exception to test whether the transaction will rollback, however,the transaction didn't rollback.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" />
So who can tell me why? thanks very muck!


Reply With Quote
