您的位置:程序门 -> java -> j2se / 基础类



使用spring管理事务不能回滚,在线等.急急急


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


使用spring管理事务不能回滚,在线等.急急急[已结贴,结贴人:5116888]
发表于:2007-03-20 17:38:16 楼主
我的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);操作中是往表中加一条记录,我加了两行是想通过数据库的唯一索引导致第二行插入失败,从而引起异常并回滚,但现在的情况是:第二行执行失败,没有插入成功.但并没有事务回滚,将第一行插入的数据回滚...
发表于:2007-03-20 17:52:211楼 得分:0
自己顶
发表于:2007-03-20 18:02:202楼 得分:30
自己写呗。
发表于:2007-03-20 18:42:323楼 得分:0
再顶
发表于:2007-03-21 13:13:584楼 得分:70
都掉线了。帮你顶上去。


快速检索

最新资讯
热门点击