Statement leak in case of "SQLGrammarException: could not extract ResultSet"

Description

I am using "javax.persistence.lock.timeout" property which can cause "org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet()" to throw "SQLGrammarException: could not extract ResultSet". This is valid and expected behavior but prevents creating SqlStatementWrapper in executeQueryStatement() ( AbstractLoadPlanBasedLoader:186 ) and that in turn means that no statement is released in finally section: AbstractLoadPlanBasedLoader.java:138 and one was created in ( AbstractLoadPlanBasedLoader.java:185 )
Additionally getResultSet() releases statement on its own in case of SQLException but not HibernateException/org.hibernate.exception.SQLGrammarException ( AbstractLoadPlanBasedLoader:L446 )

Environment

Hibernate 5.0.11, Oracle 12.1.0.2

Status

Assignee

Andrea Boriero

Reporter

Łukasz Stosik

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.11
5.1.5
5.2.9

Priority

Major