I am using hibernate 4.3.8 to connect to my MySQL 5.6 db. After awhile, my connection times out, so that the next time a db call is made, a "java.net.SocketException: Connection timed out" error is thrown. How can I have hibernate automatically reconnect to the db? This is what the data source and hibernate section of my beans file looks like:
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://url:3306/db" />
<beans:property name="username" value="username />
<beans:property name="password" value="password" />
</beans:bean>
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>Class1</beans:value>
<beans:value>Class2</beans:value>
.
.
.
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
In older versions of MySQL, I know you could just add "?autoReconnect=true " to the db url, but that has since been deprecated. I do not want to change the dataSource or use c3p0 for my connection pool if I can avoid it. Not sure if this helps, but the mysql-connector-java version is 5.1.6. I believe I need to add some properties to the hibernate properties section, any suggestions?
Aucun commentaire:
Enregistrer un commentaire