These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA/Hibernate in sailfin "Too Many Connections Exceptio
PostPosted: Mon Mar 03, 2008 1:27 pm 
Newbie

Joined: Mon Feb 25, 2008 6:31 am
Posts: 4
Hi,

I am using JPA/Hibernate to create a lib that I am using in .sar file deploying it in sailfin. all this works fine, until I have recently got the exception of "Too many connections", MySQL database is screaming of too many connections. I am giving some more details below so I can be able to identify whether it's my code in my library that is failing using Hibernate or is the sailfin connection pool that is not handling the connections how they should.

I am using a JDBC connection pool, which I have specified in persistence.xml file and that looks like:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">

<persistence-unit name="hibernatetest">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>jdbc/mysql-resource</non-jta-data-source>

<class>com.research.data.User</class>
<class>com.research.data.User_Sessions</class>
<class>com.research.data.Devices</class>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.archive.autodetection" value="class"/>

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

<!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->
</properties>

</persistence-unit>
</persistence>


When it comes to JPA/Hibernate that is how I manage EntityManager/Factory:

public class DaoImpl {

private EntityManagerFactory emf = null;
private EntityManager em = null;
private EntityTransaction entityTransaction = null;

public DaoImpl() {
emf = Persistence.createEntityManagerFactory("hibernatetest");
em = emf.createEntityManager();

}

Then I have an open() method which is called before any created queries to the database:
public void open(){

if(!em.isOpen()){
emf = Persistence.createEntityManagerFactory("hibernatetest");
em = emf.createEntityManager();
System.out.println("OPEN!");
}

}

And when I do persist any data in the database the code looks like this:

public void saveUser(User user) {
try {

entityTransaction = em.getTransaction();
entityTransaction.begin();
em.persist(user);
entityTransaction.commit();
em.close();


} catch (RuntimeException e) {
e.printStackTrace();
if(entityTransaction != null){
entityTransaction.rollback();
}
}finally{

em.close();
}
}

The I have a close() function which is called when the application is undeployed:

public void close() {

em.close();
emf.close();
}


Has anyone considered such case or seen this trouble before?

Thanks!!!
Tux


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.