zoukankan      html  css  js  c++  java
  • HibernateTemplate.save()与HibernateTemplate.update() 无法写入数据库的问题

    解决办法有两种:

    1. 将<prop key="hibernate.connection.autocommit">true</prop>设置为true即可解决,实现事务自动提交

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    	<property name="hibernateProperties">
    		<props>
    			<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    			<prop key="hibernate.show_sql">true</prop>
    			<prop key="hibernate.connection.autocommit">true</prop>
    		</props>
    	</property>
    	<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml"></property>
    </bean>

    2.使用Spring的事务管理

    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    	<property name="sessionFactory" ref="sessionFactory" />
    </bean>
    
    <aop:config>
    	<aop:pointcut expression="execution(public * service.*.*(..))" id="bussinessService" />
    	<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" />
    </aop:config>
    
    <tx:advice id="txAdvice" transaction-manager="txManager">
    	<tx:attributes>
    		<tx:method name="exists" read-only="true" />
    		<tx:method name="add*" propagation="REQUIRED" />
    	</tx:attributes>
    </tx:advice>




    如果觉得本文对您有帮助,请“打赏”,谢谢。
    您的鼓励,我的动力。
    微信 支付宝
  • 相关阅读:
    常州day2
    常州day3
    常州day1p3
    第3章 图像基础
    第2章 什么是深度学习?
    Deep Learning for Computer Vision with Python 第1章:整个内容简介
    双目视觉(1)---立体匹配介绍
    ubuntu 16.04 配置python远程jupyter nootbook环境
    Ubuntu16.04 Caffe CPU版本 安装步骤记录
    opencv(2)- 处理像素值
  • 原文地址:https://www.cnblogs.com/zongzhankui/p/5875346.html
Copyright © 2011-2022 走看看