最近小弟碰到一个很奇怪的问题,就是使用Spring+JPA+Hibernate+Oracle开发系统的时候,偶尔会出现数据提交不成功的问题。后台又没有报任何的错误,就是数据库没有记录。我个人怀疑是spring事务配置的问题,但是这种情况又不是经常出现。在此向各位大侠求助。谢谢!!!(
事务管理
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut id="serviceOperation" expression="execution(* *..*ServiceImpl.*(..))" />
<aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice" />
</aop:config>

<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
DAO 继承与jpadaosupport使用的是jpadaosupport的jpatemplate模板当调用jpatemplate.persist(entity);的时候偶尔就会出现上面描述的问题了)

解决方案 »

  1.   

            <tx:attributes>
                <tx:method name="get*" read-only="true" />
                <tx:method name="find*" read-only="true" />
                <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
            </tx:attributes>事务配得再精细点吧,最后的*包括前面的get*、find*了。
    查一下是哪些数据没有,看看相应的方法。 <aop:pointcut id="serviceOperation" expression="execution(* *..*ServiceImpl.*(..))" />这里*..*ServiceImpl.*(..),*..*ServiceImpl怎么多了一个“.”,没用过,是不管*ServiceImpl前缀多少?