Hi everyone:
I want to make the following code in the Transaction:
So I config the following spring config file:Code:public Object insertArticle(Author author, Article article) throws DataAccessException { // TODO Auto-generated method stub this.getDaofactory().getBaseDao().saveObject(author); article.setAuthor(author); int i=40/0; // throw Exception,see if the article was insert into DB Object articleID=this.getDaofactory().getBaseDao().saveObject(article); return articleID; }
if I change the code:Code:<!-- Hibernate Transaction Intercaptor --> <bean id="myHibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor"> <property name="sessionFactory"> <ref bean="MySessionFactory"/> </property> </bean> <bean id="articleBO" class="com.fangtoo.bussiness.service.ArticleBOImpl"> <property name="daofactory"> <ref bean="DAOFactory"/> </property> </bean> <bean id="daoBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"><value>user*,articleBO</value></property> <property name="interceptorNames"> <list> <value>[color=red][b][size=18][b]myHibernateInterceptor[/b][/size][/b][/color]</value> </list> </property> </bean> <bean id="myTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"> <ref bean="myTransactionManager"/> </property> <property name="transactionAttributeSource"> <value> com.fangtoo.bussiness.service.ArticleBOImpl.insert*=PROPAGATION_REQUIRED com.fangtoo.bussiness.service.ArticleBOImpl.insert*=PROPAGATION_MANDATORY </value> </property> </bean>
to the following code:Code:<list> <value>[color=red][b][size=18]myHibernateInterceptor[/size][/b][/color]</value> </list>
The transaction couldn't be rollback! Why? Why if I use HIbernateInterceptor ,the transaction can rollback, But if I use TransactionInterceptor, the transaction couldn't be rollback?!Code:<list> <value>[color=red][b][size=18]myTransactionInterceptor[/size][/b][/color]</value> </list>
Is there any incorrect config in my file?
Thks


Reply With Quote