diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java index 128d912817..2190dca45f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java @@ -161,7 +161,7 @@ public class StandardRefCursorSupport implements RefCursorSupport { // Standard JDBC REF_CURSOR support was not added until Java 8, so we need to use reflection to attempt to // access these fields/methods... try { - return (Boolean) meta.getClass().getMethod( "supportsRefCursors" ).invoke( null ); + return (Boolean) meta.getClass().getMethod( "supportsRefCursors" ).invoke( meta ); } catch (NoSuchMethodException e) { log.trace( "JDBC DatabaseMetaData class does not define supportsRefCursors method..." ); diff --git a/hibernate-core/src/test/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupportTest.java b/hibernate-core/src/test/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupportTest.java new file mode 100644 index 0000000000..9bfd2a5731 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupportTest.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.engine.jdbc.cursor.internal; + +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +import org.mockito.Mockito; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * Unit test of the {@link StandardRefCursorSupport} class. + * + * @author Daniel Heinrich + */ +@TestForIssue(jiraKey = "HHH-10612") +public class StandardRefCursorSupportTest { + + interface TestDatabaseMetaData extends DatabaseMetaData { + boolean supportsRefCursors() throws SQLException; + } + + @Test + public void testSupportsRefCursorsAboveJava8() throws Exception { + TestDatabaseMetaData metaMock = Mockito.mock(TestDatabaseMetaData.class); + Mockito.when(metaMock.supportsRefCursors()).thenReturn(true); + + boolean result = StandardRefCursorSupport.supportsRefCursors(metaMock); + assertThat(result, is(true)); + } +} \ No newline at end of file