The queryTerminatingMethods of the SharedEntityManagerCreator class does not contain the "list" method:

image-2019-07-06-14-41-13-148

In the DeferredQueryInvocationHandler class, when the EntityManager is closed, it is determined whether the method name is in "queryTerminatingMethods":

image-2019-07-06-14-43-21-734

When org.hibernate.query.Query.list() is used, and QueryImpl and NativeQueryImpl are delegated by DeferredQueryInvocationHandler, the database connection is not released:

image-2019-07-06-14-56-26-274

Comment From: sbrannen

Since org.hibernate.Query.list() is effectively an alias for javax.persistence.TypedQuery.getResultList() (which is in the queryTerminatingMethods set), why don't you just switch to using getResultList() instead of list()?

Comment From: jhoeller

Generally the JPA getResultList method should be used there, indeed... but it doesn't hurt to add Hibernate's list() variant as well. I'll add it for 5.1.9.

Comment From: wcandml

@sbrannen Yes, I can replace list with getResult, but you can't stop others from using list, so i agree with @jhoeller ,add list to avoid this problem .Thanks @sbrannen and @jhoeller .