-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate and MySQL
PostPosted: Mon Jun 01, 2009 11:00 am 
Newbie

Joined: Mon Jun 01, 2009 10:53 am
Posts: 6
Hello there,

I'm using hibernate 3 with mysql 5.1 but my connections are not being really closed.

This is an example of code where I use hibernate to list data from my MySQL database.
Code:
public Localidade localizar(Long id) {
        EntityManager em = getEntityManager();
        try {
            Query query = em.createQuery("select localidade from Localidade as localidade where localidade.id = ?1").setParameter(1, id);
            return (Localidade) query.getSingleResult();
        } catch (NoResultException ex) {
            return null;
        } finally {
            em.close();
        }
    }


I do close the connection in the finally block. But after a while I go to my MySQL manager and when I type "show full processlist;" it show a looooot of connections in the Sleep state. And I think that this is making my program run slower and slower...

How do I close these Sleep connections??

Thanks in advance.
Bruno Krebs


Top
 Profile  
 
 Post subject: Re: Hibernate and MySQL
PostPosted: Wed Jun 03, 2009 9:13 am 
Newbie

Joined: Mon Jun 01, 2009 10:53 am
Posts: 6
No one????


Top
 Profile  
 
 Post subject: Re: Hibernate and MySQL
PostPosted: Thu Jul 23, 2009 8:01 am 
Newbie

Joined: Tue Jun 30, 2009 11:03 am
Posts: 7
Hi,

I'm having the same problem as you. You can "cheat" and set the time-out to 5sec for example:
<property name="hibernate.c3p0.timeout">5</property>

But I don't like this solution, there must be a better solution than that.

Couldn't an experimented hibernate user help 2 newbies (and more I think) ?

Thank you


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

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.