Dominic Valencia
Dominic Valencia

Reputation: 11

Liferay Hibernate / Too many connections

I'm on a project now and we are building it with Liferay and Hibernate, we are almost done actually we already deploy the beta however we keep on encountering issues with regards on the database connections.

We always encounter "Too many connections".

We are using hibernate directly instead of using service builder.

My question is that isn't it possible to use Hibernate directly? Should we really use service builder? If we can use Hibernate directly can you point me on how to avoid the issue that we are encountering?

Please help me, been fixing this for days.

Regards, Dominic

P.S below is my hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">

com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">

jdbc:mysql://localhost/lportal?zeroDateTimeBehavior=convertToNull&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.connection.pool_size">100</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property> 

<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- Mapping files -->
......
</session-factory>
</hibernate-configuration>

Upvotes: 0

Views: 1211

Answers (2)

Navankur Chauhan
Navankur Chauhan

Reputation: 417

The temporary solution for this problem can be increasing the allowed maximum connections of the mysql.You can do this by the below mentioned either of the two ways.

First:

Login into the mysql server and type the below given command.

mysql> SET GLOBAL max_connections = 200;

This will increase the maximum connections.But this setting will change if the server is restarted.

Second:

Edit the file /etc/my.cnf and increase the max_connection in this file.

[mysqld]
local-infile=0
datadir=/var/lib/mysql
user=mysql
symbolic-links=0

max_connections = 100

Save the changes and type the following to restart mysqld:

/etc/init.d/mysqld restart

But this problem , usually appears because of the open connections that are not properly close and are unavailable to use.

Just try looking into all of the resources that are accessing your data base and check if all the connections are properly handled.

Hope this helps .

Upvotes: 0

Artem Khojoyan
Artem Khojoyan

Reputation: 857

I would check the code to make sure I release my connections after the usage (something like "connection.close()" in a "finally" block). You can continuously increase the maximal allowed number of connections in the configuration, but if there is a memory leak - it won't help anyway. Such things are usually fixed by refactoring the code itself.

ServiceBuilder is not a one-and-only option for Liferay, but it has so many advantages that the worth is obvious. My above idea about closing the connections is properly handled in ServiceBuilder, just like many other things.

Upvotes: 1

Related Questions