HHH-11344 : Prevent NPE when running with log on trace level

(cherry picked from commit 4ceb71f08a)
This commit is contained in:
Radim Vansa 2016-12-19 14:34:19 +01:00 committed by Gail Badner
parent 1ecc926fa1
commit 4cc22a679d
1 changed files with 4 additions and 2 deletions

View File

@ -8,6 +8,7 @@ package org.hibernate.pretty;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
@ -260,8 +261,9 @@ public final class MessageHelper {
ownerKey = collectionKey; ownerKey = collectionKey;
} }
else { else {
ownerKey = session.getPersistenceContext() Object collectionOwner = collection == null ? null : collection.getOwner();
.getEntry( collection.getOwner() ).getId(); EntityEntry entry = collectionOwner == null ? null : session.getPersistenceContext().getEntry(collectionOwner);
ownerKey = entry == null ? null : entry.getId();
} }
s.append( ownerIdentifierType.toLoggableString( s.append( ownerIdentifierType.toLoggableString(
ownerKey, session.getFactory() ) ); ownerKey, session.getFactory() ) );