Procesos pendientes en MySQL después de llamar a EntityManager.find()

I wrote a DAL which abstracts the access to the data of a MySQL DB and I'm facing an annoying problem with the processes running in MySQL.

Tengo una User Entity (targeting a User DB table) and this UserDAO

public class UserDAO {

    @PersistenceContext private EntityManager entityManager;

    public User create(User user)

    public void delete(String username)

    public User findByUsername(String username)
        User user = entityManager.find(User, username);

        return user;

    public User update(User user) {


Then this is the test I'm running:

public class DALUserTest {

    @Inject UserDAO userDAO;

    public void testGetUser() {

        User user = userDAO.findByUsername("myUsername");


The test runs properly. The problem is that if I go to the MySQL console and run the command

show processlist;

Obtengo el siguiente resultado

enter image description here

As you can see, the test execution (after its termination of course) leaves a pending process in background in MySQL, which stays there until someone kills it. Moreover, anytime I run the test it adds more and more pending processes.

Más información: yo uso persistence.xml to configure the connection. Hibernate is used as the implementation of JPA and HikariCP as the connection pool provider.

What do you think about this problem? Could it be a HikariCP (or Hibernate) bug or a wrong usage of the EntityManager class?


preguntado el 12 de junio de 14 a las 10:06

1 Respuestas

It could be HikariCP, we fixed some issues with connection cleanup at shutdown in 1.3.9 (released this week). You should upgrade if you have not already done so.

están llamar HikariDataSource.close() or HikariDataSource.shutdown(), right? If you're running in a container, you can configure the container to call one of these methods in its destruir configuration. If you do not shutdown the pool, it will indeed just abandon connections (any pool will).

If you were not calling close() or shutdown(), that would be the problem, but we of course always recommend running on the latest version of HikariCP.

Respondido el 12 de junio de 14 a las 13:06

Hi @brettw, thank you for the response. Two strange things happened: 1) I've changed the HikariCP version from 1.3.8 to 1.3.9. Running the test throws this exception stack It seems Hikari is having problems setting the minimum pool size 2) I re-tried using the Hikari 1.3.8 version. Now the problem of the processes doesn't occour again! I don't know what to say; the problem went off withoud doing nothing.. - gvdm

minimumPoolSize was deprecated in 1.3.3 and removed in 1.3.9. Use minimumIdle instead. The issue in 1.3.8 was kind of timing sensitive, so you may not always see it. I would recommend upgrading to 1.3.9 and changing minimumPoolSize a minimumIdle. - Brettw

I've done the changes you told (so now I'm using the 1.3.9 version and changed minimumPoolSize a minimumIdle). Now I get a strange error when I run the test In the persistence.xml file I have <property name="hibernate.hikari.minimumIdle" value="20"/> <property name="hibernate.hikari.maximumPoolSize" value="100"/> - gvdm

Does the error persist if you switch the order of the two parameters? I've pushed a version (1.4.0) that defers the bounds check until after all parameters have been set. It will take about 3 hours from this comment before it appears in the maven central repository. - Brettw

Ok. 1.4.0 should correct this issue. In the meantime (the next 2-3 hours), just comment out minimumIdle. - Brettw

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.