diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/internal/AbstractLoadPlanBasedLoader.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/internal/AbstractLoadPlanBasedLoader.java index a27e3bac92..75756b9b23 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/internal/AbstractLoadPlanBasedLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/internal/AbstractLoadPlanBasedLoader.java @@ -25,6 +25,7 @@ import org.hibernate.dialect.pagination.LimitHelper; import org.hibernate.dialect.pagination.NoopLimitHandler; import org.hibernate.engine.jdbc.ColumnNameCache; import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.engine.jdbc.spi.ResultSetWrapper; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.RowSelection; @@ -468,18 +469,22 @@ public abstract class AbstractLoadPlanBasedLoader { } } - private synchronized ResultSet wrapResultSetIfEnabled(final ResultSet rs, final SessionImplementor session) { - // synchronized to avoid multi-thread access issues; defined as method synch to avoid - // potential deadlock issues due to nature of code. + private ResultSet wrapResultSetIfEnabled(final ResultSet rs, final SessionImplementor session) { if ( session.getFactory().getSessionFactoryOptions().isWrapResultSetsEnabled() ) { try { if ( log.isDebugEnabled() ) { log.debugf( "Wrapping result set [%s]", rs ); } - return session.getFactory() + ResultSetWrapper wrapper = session.getFactory() .getServiceRegistry() .getService( JdbcServices.class ) - .getResultSetWrapper().wrap( rs, retreiveColumnNameToIndexCache( rs ) ); + .getResultSetWrapper(); + // synchronized to avoid multi-thread access issues + // Apparently the comment about this needing synchronization was introduced when AbstractLoadPlanBasedLoader first appeared + // in version control. Would need to investigate if it's still needed? + synchronized ( this ) { + return wrapper.wrap( rs, retreiveColumnNameToIndexCache( rs ) ); + } } catch(SQLException e) { log.unableToWrapResultSet( e );