当前位置: 首页 > 工具软件 > Open Dialect > 使用案例 >

hibernate mysql 数据源自动重连失败(could not open hibernate session for transation)

岳英锐
2023-12-01

error:could not open hibernate session for transation; nested exception is org.hibernate.transationException;JDBC begin transation failed;

org.springfarmework.transtion.cannot createTransationException: could not open hibernate session for transation; nested exception is org.hibernate.transationException;JDBC begin transation failed;


解决方法:

1:给jdbc url 增加 autoReconnect=true

jdbc.url=jdbc:mysql://localhost:3306/rongzi?useUnicode=true&characterEncoding=utf-8&autoReconnect=true

2:在sessionFactory里配置:

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.default_schema">${jdbc.default.schema}</prop>

 <prop key="hibernate.autoReconnect">true</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>cc.ccgn.rongzi.entity.mysql</value>
</list>
</property>
</bean>

 类似资料: