hibernate的配置技巧

在mysql数据库中采用主从数据库配置,在读取从库的数据时读到脏数据,并且在web容器重启之后消失,在启动之后数据库中的记录变化之后,查询的数据就是不更新,原因是数据库的链接采用了不自动提交的链接并且。在hibernate的配置文件中增加如下的参数就可以解决
<property name="hibernate.connection.autocommit">true</property>


在数据库连接池链接数据库之后,数据库重启之后,web容器不重启的情况下,访问数据库的API就一直报错,
org.hibernate.exception.JDBCConnectionException: could not execute query


Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:


** BEGIN NESTED EXCEPTION **

com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

STACKTRACE:

java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.


在hibernate的配置文件中增加如下的参数就可以解决

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值