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

使用Spring管理事务不能回滚,

2011-12-25 
使用Spring管理事务不能回滚,在线等.急急急我的applicationcontext.xml代码:?xmlversion 1.0 encoding

使用Spring管理事务不能回滚,在线等.急急急
我的applicationcontext.xml代码:
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<!DOCTYPE   beans   PUBLIC   "-//SPRING//DTD   BEAN//EN "   "http://www.springframework.org/dtd/spring-beans.dtd ">
<beans>
<import   resource= "/conf/sysmgr/rolesMgr/rolesMgrSpring.xml "   />
<import   resource= "/conf/sysmgr/userMgr/userMgrSpring.xml "   />
<import   resource= "/conf/sysmgr/reinsurer/reinsurerSpring.xml "   />
<import   resource= "/conf/sysmgr/product/insmgrSpring.xml "   />
<import   resource= "/conf/sysmgr/login/loginSpring.xml "   />
<import   resource= "/conf/contract/mreinagmntSpring.xml "   />
<import   resource= "/conf/operadata/datamodify/chkerrlistSpring.xml "   />
<import
resource= "/conf/operadata/datarecord/gpolicy/gpolicySpring.xml "   />
<import
resource= "/conf/operadata/datarecord/liabamt/liabamtSpring.xml "   />
<import
resource= "/conf/operadata/datarecord/policlm/policlmSpring.xml "   />
<import
resource= "/conf/operadata/datarecord/polidiv/polidivSpring.xml "   />
<import
resource= "/conf/operadata/datarecord/poliloan/poliloanSpring.xml "   />
<import
resource= "/conf/operadata/datarecord/polimdf/polimdfSpring.xml "   />
<import
resource= "/conf/operadata/datarecord/poliprm/poliprmSpring.xml "   />
<import
resource= "/conf/operadata/datarecord/spolicy/spolicySpring.xml "   />
<import
resource= "/conf/reindatamgr/redatamade/reinagmnt_fSpring.xml "   />
<import
resource= "/conf/reindatamgr/reindatamodify/repolicySpring.xml "   />

<bean   id= "MyData "
class= "org.springframework.jdbc.datasource.DriverManagerDataSource ">
<property   name= "driverClassName ">
<value> oracle.jdbc.driver.OracleDriver </value>
</property>
<property   name= "url ">
<value> jdbc:oracle:thin:@10.203.14.132:1521:remotedb </value>
</property>
<property   name= "username ">
<value> reinadm </value>
</property>
<property   name= "password ">
<value> cpic </value>
</property>
</bean>
<bean   id= "MySessionFactory "
class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property   name= "dataSource ">
<ref   bean= "MyData "   />
</property>
<property   name= "hibernateProperties ">
<props>
<prop   key= "hibernate.dialect ">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop   key= "hibernate.show_sql "> true </prop>
</props>
</property>
<property   name= "mappingResources ">
<list>
<value> com/inspur/hbm/funcInfo.hbm.xml </value>
<value> com/inspur/hbm/Rolefunc.hbm.xml </value>
<value> com/inspur/hbm/Roleinfo.hbm.xml </value>
<value> com/inspur/hbm/Userinfo.hbm.xml </value>


<value> com/inspur/hbm/Classcode.hbm.xml </value>
<value> com/inspur/hbm/Product.hbm.xml </value>
<value> com/inspur/hbm/Reinsurer.hbm.xml </value>
<value> com/inspur/hbm/Openwin.hbm.xml </value>
<value> com/inspur/hbm/ChkErrList.hbm.xml </value>
<value> com/inspur/hbm/Mreinagmnt.hbm.xml </value>
<value> com/inspur/hbm/Organ.hbm.xml </value>
<value> com/inspur/hbm/Avramt.hbm.xml </value>
<value> com/inspur/hbm/GPolicy.hbm.xml </value>
<value> com/inspur/hbm/SPolicy.hbm.xml </value>
<value> com/inspur/hbm/LiabAmt.hbm.xml </value>
<value> com/inspur/hbm/PoliClm.hbm.xml </value>
<value> com/inspur/hbm/PoliDiv.hbm.xml </value>
<value> com/inspur/hbm/PoliLoan.hbm.xml </value>
<value> com/inspur/hbm/PoliMdf.hbm.xml </value>
<value> com/inspur/hbm/PoliPrm.hbm.xml </value>
<value> com/inspur/hbm/Reinagmnt_f.hbm.xml </value>
<value> com/inspur/hbm/Repolicy.hbm.xml </value>

</list>
</property>
</bean>
<bean   id= "iBaseObject "
class= "com.inspur.common.dao.BaseObjectDAO ">
<property   name= "mySessionFactory ">
<ref   bean= "MySessionFactory "   />
</property>
</bean>

<bean   id= "transactionManager "
class= "org.springframework.orm.hibernate3.HibernateTransactionManager ">
<property   name= "sessionFactory ">
<ref   local= "MySessionFactory "   />
</property>
</bean>
<!--     定义事务拦截器bean> -->
<bean   id= "transactionInterceptor "
class= "org.springframework.transaction.interceptor.TransactionInterceptor ">
<!--     事务拦截器bean需要依赖注入一个事务管理器-->
<property   name= "transactionManager ">
<ref   local= "transactionManager "   />
</property>
<property   name= "transactionAttributes ">
<!--     下面定义事务传播属性-->
<props>
<prop   key= "add* "> PROPAGATION_REQUIRED </prop>
</props>
</property>
</bean>

<!--定义一个BeanPostProcessor   beanSpring提供BeanPostProcessor的实现类BeanNameAutoProxyCreator-->

<bean
class= "org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator ">
<!--     指定对满足哪些bean   name的bean自动生成业务代理   -->
<property   name= "beanNames ">
<!--     此处还可以列出更多的需要生成事务代理的目标bean-->
<list>
<value> iBaseObject </value>
</list>
<!--     有一个需要生成事务代理的目标bean,   此处就增加一行-->
</property>
<!--     下面定义BeanNameAutoProxyCreator所需要的事务拦截器-->
<property   name= "interceptorNames ">
<list>
<value> transactionInterceptor </value>
<!--   此处还增加其他新的Interceptor   -->
</list>
</property>
</bean>

</beans>


DAO层代码:
public   void   add(IBasePOJO   IBasePOJO)   throws   HibernateException{


HibernateTemplate   hibernateTemplate   =   new   HibernateTemplate(getMySessionFactory());
hibernateTemplate.save(IBasePOJO);
hibernateTemplate.save(IBasePOJO);
}
上面的hibernateTemplate.save(IBasePOJO);操作中是往表中加一条记录,我加了两行是想通过数据库的唯一索引导致第二行插入失败,从而引起异常并回滚,但现在的情况是:第二行执行失败,没有插入成功.但并没有事务回滚,将第一行插入的数据回滚...

[解决办法]
自己写呗。

[解决办法]
都掉线了。帮你顶上去。

热点排行