关于Spring事务控制中Exception的处理讨论!(AssertionFailure: an assertion failure occured)这个问题困扰我好久了,请大家帮忙。我的系统如下:Spring + Hibernate, 在spring的事务设置:
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean><tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"  />
<tx:method name="upload*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>现在在一个for循环中调用先调用Dao.find()方法查询数据,紧接着调用Dao.add()方法插入数据。现在的问题是,第一次执行时,Dao.find()方法没有问题通过,但当Dao.add()方法抛出hibernate异常,然后我catch掉它,让下一个循环继续,这是执行Dao.find()方法时就出问题了,抛出:
AssertionFailure: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in com.xxxx.xxx.model.xxxxVo entry (don't flush the Session after an exception occurs)就是说前一个方法出了一场,但被我catch住,但接下来就无法执行其他数据库操作了!请问如何解决阿!我的代码大致如下:
........
for
{
    Dao.find();//此方法没有事务控制
    try
    {
       Dao.add();//此方法有事务控制,详见上面配置
    }
    catch(Exception ex)
    {
       //不再抛出所有异常,由于某些商业原因
    }
}
.........