我为了解决hibernate连mysql数据库的长时间没有处理后数据库访问异常(com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.),引入了c3p0库,但配置重启后问题依旧,不知道是不是哪些地方配置的有问题,请各位大侠指点!
mysql的配置:
interactive_timeout=20
wait_timeout=20hibernate.cfg.xml:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name= "hibernate.connection.provider_class ">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">20</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.timeout">20</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">20</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.automaticTestTable">true</property>
<property name="hibernate.c3p0.idleConnectionTestPeriod">20</property>
<property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="show_sql">true</property>
<mapping resource="entity/config.hbn.xml"/>
</session-factory>
</hibernate-configuration>
mysql的配置:
interactive_timeout=20
wait_timeout=20hibernate.cfg.xml:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name= "hibernate.connection.provider_class ">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">20</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.timeout">20</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">20</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.automaticTestTable">true</property>
<property name="hibernate.c3p0.idleConnectionTestPeriod">20</property>
<property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="show_sql">true</property>
<mapping resource="entity/config.hbn.xml"/>
</session-factory>
</hibernate-configuration>
解决方案 »
- 怎样将xls文件数据导入并保存在session中!!!急。。。。。
- 用JAVA做中型企业门户,采用什么框架合适?
- tomcat 404 错误怎么解决,急,在线等。
- 使用POI组件导出的excel怎么导到服务器上了,请高人帮忙!急!!百分重谢!
- 文本域输入几段内容的传递及存储
- 我从lomozes下了一个lomboz-eclipse-emf-gef-jem-I20050526.zip,可是在preference里没有lomboz选项???
- 请大虾们帮个忙:中文问题怎么解决呀.
- multipart/form-data form用这种方式如何获取参数
- 在tomcat里怎么如何去掉目录浏览属性呀
- Spring Acegi中怎么动态判断用户权限
- java 针对 txt文本 输出流 输入流。
- 小乱码?
给个关注奖吧!
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>