Hibenate 缓存导致事务无法提交

使用Spring管理Hibernate事务,明明能正常打印出SQL 语句 ,也没有报异常,但却无法执行Save()操作(貌似写入操作都无法执行,数据自然是没有变化的),纠结了N久,才查到没有设置Hibernate 自动提交。需要增加下面的配置:项目使用Hibernate4,Spring3,Struts2 框架 。

<property name="connection.autocommit">true</property>

(<!-- 设置事务自动提交(默认为false,false的话,程序对数据库的操作都不会作为事务提交) -->)

附录为事务配置:

<bean name="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
        <property name="autodetectDataSource" value="false"/>
</bean>
    
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="modify*" propagation="REQUIRED"/>
            <tx:method name="del*" propagation="REQUIRED"/>
            <tx:method name="insert" propagation="REQUIRED"/>
            <tx:method name="handle*" propagation="REQUIRED"/>
            <tx:method name="*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    
    <aop:config>
        <aop:pointcut expression="execution(* com.ssh.service.*.*(..))" id="allManagerMethod"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
    </aop:config>

 

posted @ 2013-12-01 19:40  叶汉城  阅读(706)  评论(0编辑  收藏  举报