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