论坛首页 入门技术论坛

spring 对hibernate 事务管理问题

浏览 1947 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-11-30  
spring 版本为2.0.7 hibernate版本为3.2.5.ga


spring 配置文件为






   <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
              <property name="jndiName" value="java:comp/env/jdbc/jdbm"/>
          </bean>


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"  destroy-method="close">
<property name="dataSource" ref="dataSource" />



<property name="mappingLocations">
<list>
<value>classpath*:com/jdapp/db/cc/po/*.hbm.xml</value> 
          

</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.chche.provider_class">org.hibernate.cache.EhCacheProvider</prop>

<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>


</props>
</property>

<property name="eventListeners">
<map>
<entry key="merge">
<bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
</entry>
</map>
</property>
        </bean>


   <!-- Transaction manager for hibernate  -->
    <bean id="myTransactionManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory"> 
     <ref bean="sessionFactory" /> 
    </property> 
  </bean>
 
 
   <!-- hibernate Dao  -->
   <bean id="testDao" class="com.jdapp.db.cc.dao.TestDao"> 
   <property name="sessionFactory"> 
    <ref bean="sessionFactory" /> 
   </property> 
  </bean> 


  <bean id="testTarget" class="com.jdapp.db.cc.dao.TargetLogic"> 
  <property name="testDao"> 
   <ref local="testDao" /> 
  </property> 
</bean> 

<bean id="userDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="myTransactionManager" />
</property>
<property name="target">
<ref local="testDao" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save">PROPAGATION_REQUIRED,-Exception</prop>

</props>
</property>
</bean>

源代码程为 TestDao.java

package com.jdapp.db.cc.dao;

import java.sql.SQLException;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;




import com.jdapp.db.cc.po.Depinfo;

public class TestDao  extends HibernateDaoSupport implements TargetLogicInc

{


public void save(Depinfo de)


{
System.out.println(this.getHibernateTemplate().find(" from Depinfo").size());

  


try {
this.getHibernateTemplate().save(de);
if(true) {
throw new Exception();

}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}






}




}


按照我的意愿,应该不会向数据库交提, 但结果每次都向数据库提交了.请大家看看我的代码什么地方出了问题?
   发表时间:2007-11-30  
我的TargetLogic是没用的
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics