下面是我的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);
//现在这个保存和更新操作是要同时操作的,如果有一个失败 要做回滚。但是现在我保存方法成功了,更新操作不成功,但是数据持久化到数据库中了。请问是什么问题?
}
<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);
//现在这个保存和更新操作是要同时操作的,如果有一个失败 要做回滚。但是现在我保存方法成功了,更新操作不成功,但是数据持久化到数据库中了。请问是什么问题?
}
解决方案 »
- 提问:oracle在开发ssh2中需要注意哪些问题?
- mySmartUpload.setMaxFileSize(10000);文件大小限制是以K为单位吗?
- 麻烦各位热心的大虾帮帮我有关在Jsp中使用日期控件出现的问题!
- 请大家帮个忙看一下是什么问题!
- 关于tomcat的问题
- JSP和Bean的问题!
- 怎样让一个图片和按钮的问题
- 高分求解如果改遍png图像的灰度呢???
- 介绍实例或者写点源码看看!高手请进!
- 从 Ms Sql Server 2000 中读出 text类型的数据,最好有源程序 (在线等待) ,我是用jsp
- javaweb框架书籍?
- setObject将对象二进制数据存入数据库之后,读取时类型丢失
<property name="beanNames">
<value>friendMger</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
上面红色颜色处导致你的处理不能属于同一个事务;
<value>friendMger</value> 这个地方一般都会配置成*XXXX,
然后写的service或service接口就要对应*XXXX 这种形式;
如:我配置<value>*Service</value>,那我写的所有service接口,都以这中格式命名,
如 FriendManagerService,这样, 这个service才能被spring管理到,
然后上面的那些什么<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop>才会被应用上。楼主试试吧,多看点资料!