We're updating the issue view to help you get more done. 

Connection leak when SQLGrammarException is thrown

Description

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.

Environment

Hibernate 5.2.2.Final and newer, mysql database.

Status

Assignee

Andrea Boriero

Reporter

Cristian Oneț

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.2
5.2.5

Priority

Major