I'm pretty sure that there is an issue introduced in Hibernate 5.2.2 related to connection release when an SQLGrammarException is thrown.
I discovered this in the following scenario:
1. Take a Spring application using JPA2 and hickaricp/c3p0 connection pool
2. Trigger an SQLGrammarException by messing up the schema
3. Each failed JPA query will leak one connection eventually starving the pool
I attached two test cases, run the JPAUnitTestCase in each project. With hibernate 5.2.1.Final the connection pool does not get exhausted while using 5.2.2.Final the following error is obtained: "javax.persistence.PersistenceException: org.hibernate.HibernateException: The internal connection pool has reached its maximum size and no connection is currently available!"
I'm pretty sure that the test case replicates what is happening in the Spring application.
Hibernate 5.2.2.Final and newer, mysql database.