hibernate/hibernate-orm — pull request #488 by lukasz-antoniak (2013-03-21 08:38:52+00:00)
Title: HHH-7984 - Oracle callable statement closing

Patch and test for HHH-7984 JIRA ticket.
Link: https://hibernate.atlassian.net/browse/HHH-7984

Issues:

1. Execution of native PL/SQL function returns OracleCallableStatementWrapper which is registered in JdbcCoordinatorImpl#xref via Loader#prepareQueryStatement(String, QueryParameters, LimitHandler, boolean, SessionImplementor) -> StatementPreparerImpl# prepareQueryStatement(String, boolean, ScrollMode) -> QueryStatementPreparationTempl and so on... ResultSet generated from OracleCallableStatementWrapper is than passed to JdbcCoordinatorImpl#register(ResultSet). In this case ResultSet#getStatement() does not return original OracleCallableStatementWrapper, but T4CStatement. Both objects are not equal and LOG.unregisteredStatement() message is logged. This results in two objects registered in JdbcCoordinatorImpl#xref representing the same PL/SQL call.
2. Loader#doQuery(SessionImplementor, QueryParameters, boolean, ResultTransformer) retrieves statement from ResultSet and closes it by invoking ``session.getTransactionCoordinator().getJdbcCoordinator().release( st )`` (st points to T4CStatement). This results in unclosed cursor.

Proposed solution:

1. Pass original Statement during ResultSet registration. This way JdbcCoordinatorImpl#xref doesn't contain two object representing the same PL/SQL call.
2. Encapsulate original Statement and ResultSet in SqlStatementWrapper. Closing OracleCallableStatementWrapper (not T4CStatement) releases database cursor.

Regards,
Lukasz Antoniak