spring 对hibernate 事务管理问题
spring 版本为2.0.7 hibernate版本为3.2.5.ga
spring 配置文件为
<bean id="dataSource" value="java:comp/env/jdbc/jdbm"/>
</bean>
<bean id="sessionFactory"
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
/>
</entry>
</map>
</property>
</bean>
<!-- Transaction manager for hibernate -->
<bean id="myTransactionManager" />
</property>
</bean>
<!-- hibernate Dao -->
<bean id="testDao" />
</property>
</bean>
<bean id="testTarget" />
</property>
</bean>
<bean id="userDAOProxy"
/>
</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();
}
}
}
按照我的意愿,应该不会向数据库交提, 但结果每次都向数据库提交了.请大家看看我的代码什么地方出了问题?
1 楼 fty001 2007-11-30 我的TargetLogic是没用的