无法释放JDBC连接

时间:2016-12-12 13:02:59

标签: hibernate jpa

我是JPA& amp;的新手。 Hibernate,我正在执行重置密码操作。在这种情况下,实体对象(用户)在我尝试登录之后会更新,但不幸的是,服务器挂起,我得到了以下异常。

javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Unable to release JDBC Connection

以下是我们的持久性文件配置

<properties>

  <!-- Configuring JDBC properties -->
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/dbname?autoReconnect=true&amp;useUnicode=true" />
  <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
  <property name="javax.persistence.jdbc.user" value="username" />
  <property name="javax.persistence.jdbc.password" value="password" />
  <property name="hibernate.jdbc.batch_size" value="80000" />
  <property name="hibernate.show_sql" value="false" />
  <property name="hibernate.format_sql" value="false" />
  <property name="hibernate.use_sql_comments" value="false" />
  <property name="hibernate.hbm2ddl.auto" value="none" />
  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
  <property name="hibernate.connection.charSet" value="UTF-8" />
  <property name="hibernate.max_fetch_depth" value="2" />

  <!-- Configuring Connection Pool -->
  <property name="hibernate.c3p0.min_size" value="10" />      
  <property name="hibernate.c3p0.max_size" value="250" />
  <property name="hibernate.c3p0.acquire_increment" value="10"/>
  <property name="hibernate.c3p0.timeout" value="500" />
  <property name="hibernate.c3p0.max_statements" value="50" />
  <property name="hibernate.c3p0.idle_test_period" value="2000" />

  <!-- Newly added -->
  <property name="hibernate.c3p0.maxConnectionAge" value="300"/>
  <property name="hibernate.c3p0.maxIdleTimeExcessConnections" value="300"/>
  <property name="hibernate.c3p0.testConnectionOnCheckin" value="true"/>
  <property name="hibernate.c3p0.preferredTestQuery" value="select 1"/>
  <property name="hibernate.c3p0.validate" value="false"/>
  <property name="hibernate.c3p0.testConnectionOnCheckout" value="false" />
</properties>

任何人都可以帮我解决错误吗?我在配置文件中遗漏了什么?

1 个答案:

答案 0 :(得分:1)

这是我的设置,适用于hibernate 5.2.4和spring mvc 4.3.4和Maven 3.3.9

<!-- Set Up data base DataSource and the connection pool -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
      destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mySchemaName?useSSL=false" />
    <property name="user" value="root" />
    <property name="password" value="**********" /> 

    <!-- the connection pool properties for C3P0 -->
    <property name="minPoolSize" value="5" />
    <property name="maxPoolSize" value="20" />
    <property name="maxIdleTime" value="30000" />
</bean>  

<!-- Setu session factory for Hibernate -->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.package.whatever" />
    <property name="hibernateProperties">
       <props>
          <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
          <prop key="hibernate.show_sql">true</prop>
       </props>
    </property>

<!--  Setup Hibernate transaction manager -->
<bean id="myTransactionManager"
        class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

    

提示: 如果您正在使用 glassfish服务器4.1.1 ,您必须找到glasfish / domains / domain1 / modules并替换jboss-记录器与最新的jboss-logger 3.3.0