CODEXE

Hibernate Communication Link Failure

Use C3P0 connection pool to manage

Import  hibernate-c3p0.jar the in your project


	<dependency>
	    < groupId>org.hibernate</groupId>
	    < artifactId>hibernate-core</artifactId>
	    < version>5.2.10.Final</version>
	</dependency>
	
	<!-- Hibernate c3p0 connection pool -->
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-c3p0</artifactId>
		<version>5.2.10.Final</version>
	</dependency>
			

Configure the C3P0 in the hibernate configuration file


<hibernate-configuration>
 <session-factory name="as">
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <!-- database details -->
  <property name="hibernate.connection.url">...</property>
  <property name="hibernate.connection.username">....</property>
  <property name="hibernate.connection.password">....</property>
  <property name="hibernate.current_session_context_class">thread</property>
  
  <property name="hibernate.c3p0.min_size">5</property>
  <property name="hibernate.c3p0.max_size">20</property>
  <property name="hibernate.c3p0.timeout">3000</property>
  <property name="hibernate.c3p0.max_statements">50</property>
  <property name="hibernate.c3p0.idle_test_period">300</property>
  

 </session-factory>
</hibernate-configuration>
			

hibernate.c3p0.min_size – Minimum number of JDBC connections in the pool. Hibernate default: 1
hibernate.c3p0.max_size – Maximum number of JDBC connections in the pool. Hibernate default: 100
hibernate.c3p0.timeout – When an idle connection is removed from the pool (in second). Hibernate default: 0, never expire.
hibernate.c3p0.max_statements – Number of prepared statements will be cached. Increase performance. Hibernate default: 0 , caching is disable.
hibernate.c3p0.idle_test_period – idle time in seconds before a connection is automatically validated. Hibernate default: 0
Value of timeout should be larger than test period.