日期:2014-05-17  浏览次数:20736 次

SSH事务不能回滚问题,求好人解答
本帖最后由 yuandaobo 于 2013-03-11 09:22:01 编辑
项目结构大致分为三层。数据库访问层dao、业务处理层biz、action层
现在我将事务配置加在了biz层,当biz层里面有两个数据库操作时,其中一个会出错(故意让其出错的),但是第一个数据库操作还是成功了,没有回滚,不知道是什么原因。下面是sping里面的事务配置:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>

<!-- 配置事务管理器 -->      
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">    
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>    
        
  <!-- 配置事务特性 ,配置add、delete和update开始的方法,事务传播特性为required -->           
    <tx:advice id="txAdvice" transaction-manager="transactionManager">    
        <tx:attributes> 
            <tx:method name="update*" propagation="REQUIRED"/>  
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="del*" propagation="REQUIRED"/>
            <tx:method name="*" propagation="REQUIRED" read-only="true"/>    
        </tx:attributes>    
    </tx:advice>   
        
    <!-- 配置那些类的方法进行事务管理,当前com.ilb.dao包中的子包、类中所有方法需要,还需要参考tx:advice的设置 -->    
    <aop:config>    
        <aop:pointcut id="allManagerMethod" expression="execution (* com.cloudsoar3c.biz.impl.*.*(..))"/>    
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
    </aop:config>  
    
    <tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />

好人路过帮看看,谢谢
下面是部分代码:
DAO层代码:

public void add(Object ogj) throws Exception{
super.getHibernateTemplate().getSessionFactory().getCurrentSession().save(ogj);
}

biz层代码:
public TOrder addNewOrder(Integer buyCount, TClient client)throws Exception{
TServerHostLicense serverHostLicense = new TServerHostLicense();
serverHostLicense.setHostId(System.currentTimeMillis()+"");
serverHostLicense.setAddTime(new Date());
serverHostLicense.setHostName("测试主机名");
serverHostLicense.setLicenseFile("licenseFile........");
serverHostLicense.setStatus(-1);
serverHostLicense.setSupportClientCount(buyCount);
serverHostLicense.setTClient(client);
//添加主机服务器信息
//b