日期:2014-05-17  浏览次数:20749 次

spring 事务配置不回滚的问题。急
下面是我的spring 事务的配置

<!-- AOP事务管理 -->
<bean id="transactionManager"  
  class="org.springframework.orm.hibernate3.HibernateTransactionManager" >  
  <property name="sessionFactory">  
  <ref bean="sessionFactory" />  
  </property>  
  </bean><!-- 拦截事务Beans设置-->

<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor" lazy-init="true">
  <property name="transactionManager" ref="transactionManager" /> 
  <property name="transactionAttributes">  
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="exec*">PROPAGATION_REQUIRED,-Exception</prop>
  <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> 
</props>
  </property>  
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>friendMger</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>  
///////////////////////////////////////////////////////////////////////////////////////////////////
 <bean id="friendMger" class="com.friend.service.impl.FriendManagerImpl" >
<property name="friendDao" ref="friendDao"></property>
</bean>
<bean id="friendDao" class="com.oooo3d.hizone.friend.dao.impl.FriendDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>

现在我在service中
public class FriendManagerImpl implements FriendManager {
 
private FriendDao friendDao;


public FriendDao getFriendDao() {
return friendDao;
}


public void setFriendDao(FriendDao friendDao) {
this.friendDao = friendDao;
}


public void addFollowingUsers(String currentusrID, String accnt) {

Friend friendtest=new Friend();
friendtest.setFollowSerial(11);
friendDao.addUsers(friendtest);
  friendDao.updateUsers(friendtest);
//现在这个保存和更新操作是要同时操作的,如果有一个失败 要做回滚。但是现在我保存方法成功了,更新操作不成功,但是数据持久化到数据库中了。请问是什么问题?


}

------解决方案--------------------
楼主,你的问题出在自动代理处,没写对,或者叫你的service没有与此处的配置对应上
XML code

<bean class="org.springframew