From acd2f238ee7435ccf80565a53a67b012b01a62f7 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Thu, 7 Jul 2016 13:26:06 -0500 Subject: [PATCH] HHH-10905 - Fix NPE when calling StatelessSession methods with null LockMode. --- .../org/hibernate/internal/StatelessSessionImpl.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index 12baa68b62..873308ba64 100755 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -178,8 +178,9 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen @Override public Object get(String entityName, Serializable id, LockMode lockMode) { checkOpen(); + Object result = getFactory().getMetamodel().entityPersister( entityName ) - .load( id, null, lockMode, this ); + .load( id, null, getNullSafeLockMode( lockMode ), this ); if ( temporaryPersistenceContext.isLoadFinished() ) { temporaryPersistenceContext.clear(); } @@ -227,7 +228,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen Object result = null; try { this.getLoadQueryInfluencers().setInternalFetchProfile( "refresh" ); - result = persister.load( id, entity, lockMode, this ); + result = persister.load( id, entity, getNullSafeLockMode( lockMode ), this ); } finally { this.getLoadQueryInfluencers().setInternalFetchProfile( previousFetchProfile ); @@ -669,4 +670,8 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen private JtaPlatform getJtaPlatform() { return getFactory().getServiceRegistry().getService( JtaPlatform.class ); } + + private LockMode getNullSafeLockMode(LockMode lockMode) { + return lockMode == null ? LockMode.NONE : lockMode; + } }