首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

为什么TransactionInterceptor遇到exception就是没有回滚,是否该用RuntimeException

2014-01-26 
配置文件:bean idtransactionManager classorg.springframework.orm.hibernate3.HibernateTransactio

配置文件: 
    
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
  <ref bean="forumSessionFactory" />
  </property>
  </bean>
 
  <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager">
  <ref bean="transactionManager"/>
  </property>
  <property name="transactionAttributes">
  <props>
  <prop key="add*">PROPAGATION_REQUIRED</prop>
  <prop key="update*">PROPAGATION_REQUIRED <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
  </props>
  </property>
  </bean>
 
  <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
  <constructor-arg>
  <ref bean="transactionInterceptor"/>
  </constructor-arg>
  </bean>
 
 
  <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="beanNames">
  <value>*Service</value>
  </property>
  <property name="interceptorNames">
  <list>
    <value>transactionInterceptor</value>
  </list>
  </property>
  </bean>
 
 
  <bean id="userService" class="com.class8.service.impl.UserServiceImpl" />
 
  tomcat能够正常启动成功...但是当userService出现java.lang.NullPointerException
  的时候事务不能回滚...发生错误 

------解决方法--------------------------------------------------------
userService出现java.lang.NullPointerException的方法名什么?
 
  把
  <prop key="add*">PROPAGATION_REQUIRED</prop>
  <prop key="update*">PROPAGATION_REQUIRED
  <prop key="delete*">PROPAGATION_REQUIRED</prop>
  <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
 
  换成
 
  <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
  <prop key="add*">PROPAGATION_REQUIRED</prop>
  <prop key="update*">PROPAGATION_REQUIRED         

热点排行