From 164cbf0e8b42e9dad73ab04b3f1dc01c933c3a71 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 3 Jul 2024 11:13:32 +0200 Subject: [PATCH] HHH-18313 NullPointerException because JdbcIsolationDelegate.sqlExceptionHelper() returns null --- .../internal/JdbcEnvironmentInitiator.java | 10 ++++++++++ .../jdbc/internal/JdbcCoordinatorImpl.java | 4 ++-- .../jdbc/internal/JdbcServicesImpl.java | 18 ++++++------------ .../LogicalConnectionManagedImpl.java | 19 ++++++++++++++++--- .../resource/jdbc/spi/JdbcSessionOwner.java | 5 +++++ .../jdbc/internal/JdbcIsolationDelegate.java | 2 +- .../jta/internal/JtaIsolationDelegate.java | 2 +- .../connection/ConnectionCreatorTest.java | 11 ++++++++++- .../orm/test/jdbc/JdbcCoordinatorTest.java | 2 +- 9 files changed, 52 insertions(+), 21 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java index 229bb352b2..0cc9afb633 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java @@ -28,6 +28,7 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl; import org.hibernate.engine.jdbc.internal.JdbcServicesImpl; import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.event.internal.EmptyEventManager; import org.hibernate.event.spi.EventManager; @@ -278,6 +279,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator R getService(Class serviceRole) { if ( JdbcServices.class.equals( serviceRole ) ) { // return a new, not fully initialized JdbcServicesImpl - return (R) new JdbcServicesImpl(); + JdbcServicesImpl jdbcServices = new JdbcServicesImpl(this); + jdbcServices.configure( new HashMap<>() ); + return (R) jdbcServices; + } + if( JdbcEnvironment.class.equals( serviceRole ) ){ + return (R) new JdbcEnvironmentImpl( this, new H2Dialect() ); } return super.getService( serviceRole ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/JdbcCoordinatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/JdbcCoordinatorTest.java index b02f25dcbf..dc0b6ce6df 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/JdbcCoordinatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/JdbcCoordinatorTest.java @@ -79,7 +79,7 @@ public class JdbcCoordinatorTest { SqlExceptionHelper sqlExceptionHelper = Mockito.mock( SqlExceptionHelper.class ); when( jdbcServices.getSqlExceptionHelper() ).thenReturn( sqlExceptionHelper ); - + when(sessionOwner.getSqlExceptionHelper()).thenReturn( sqlExceptionHelper ); JdbcCoordinatorImpl jdbcCoordinator = new JdbcCoordinatorImpl( null, sessionOwner,