• 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>




    如果觉得本文对您有帮助,请“打赏”,谢谢。
    您的鼓励,我的动力。
    微信 支付宝
  • 相关阅读:
    蓝牙遐想
    BT stack浅入了解
    集合(set)
    字典练习
    数据类型--字典
    数据类型--元组
    字符串
    深浅copy
    python---list
    三种Div高度自适应的方法
  • 原文地址:https://www.cnblogs.com/zongzhankui/p/5875346.html
Copyright © 2020-2023  润新知