HHH-11097 - Performance problem if cached entity has attribute state with an expensive toString() method (LOB, etc)

This commit is contained in:
Steve Ebersole 2016-09-13 21:10:23 -05:00
parent c7c9e42145
commit 0a2a5c622e
5 changed files with 34 additions and 7 deletions

View File

@ -179,7 +179,23 @@ public abstract class CollectionType extends AbstractType implements Association
if ( value == null ) { if ( value == null ) {
return "null"; return "null";
} }
else if ( !Hibernate.isInitialized( value ) ) {
if ( !getReturnedClass().isInstance( value ) && !PersistentCollection.class.isInstance( value ) ) {
// its most likely the collection-key
final CollectionPersister persister = getPersister( factory );
if ( persister.getKeyType().getReturnedClass().isInstance( value ) ) {
return getRole() + "#" + getPersister( factory ).getKeyType().toLoggableString( value, factory );
}
else {
// although it could also be the collection-id
if ( persister.getIdentifierType() != null
&& persister.getIdentifierType().getReturnedClass().isInstance( value ) ) {
return getRole() + "#" + getPersister( factory ).getIdentifierType().toLoggableString( value, factory );
}
}
}
if ( !Hibernate.isInitialized( value ) ) {
return "<uninitialized>"; return "<uninitialized>";
} }
else { else {
@ -289,7 +305,11 @@ public abstract class CollectionType extends AbstractType implements Association
* @return The underlying collection persister * @return The underlying collection persister
*/ */
private CollectionPersister getPersister(SharedSessionContractImplementor session) { private CollectionPersister getPersister(SharedSessionContractImplementor session) {
return session.getFactory().getMetamodel().collectionPersister( role ); return getPersister( session.getFactory() );
}
private CollectionPersister getPersister(SessionFactoryImplementor factory) {
return factory.getMetamodel().collectionPersister( role );
} }
@Override @Override

View File

@ -499,8 +499,15 @@ public abstract class EntityType extends AbstractType implements AssociationType
return "null"; return "null";
} }
EntityPersister persister = getAssociatedEntityPersister( factory ); final EntityPersister persister = getAssociatedEntityPersister( factory );
StringBuilder result = new StringBuilder().append( associatedEntityName ); if ( !persister.getEntityTuplizer().isInstance( value ) ) {
// it should be the id type...
if ( persister.getIdentifierType().getReturnedClass().isInstance( value ) ) {
return associatedEntityName + "#" + value;
}
}
final StringBuilder result = new StringBuilder().append( associatedEntityName );
if ( persister.hasIdentifierProperty() ) { if ( persister.hasIdentifierProperty() ) {
final Serializable id; final Serializable id;

View File

@ -63,7 +63,7 @@ public class BlobTypeDescriptor extends AbstractTypeDescriptor<Blob> {
@Override @Override
public String extractLoggableRepresentation(Blob value) { public String extractLoggableRepresentation(Blob value) {
return value == null ? "null" : "BLOB{...}"; return value == null ? "null" : "{blob}";
} }
@Override @Override

View File

@ -57,7 +57,7 @@ public class ClobTypeDescriptor extends AbstractTypeDescriptor<Clob> {
@Override @Override
public String extractLoggableRepresentation(Clob value) { public String extractLoggableRepresentation(Clob value) {
return value == null ? "null" : "CLOB{...}"; return value == null ? "null" : "{clob}";
} }
public String toString(Clob value) { public String toString(Clob value) {

View File

@ -57,7 +57,7 @@ public class NClobTypeDescriptor extends AbstractTypeDescriptor<NClob> {
@Override @Override
public String extractLoggableRepresentation(NClob value) { public String extractLoggableRepresentation(NClob value) {
return value == null ? "null" : "NCLOB{...}"; return value == null ? "null" : "{nclob}";
} }
public String toString(NClob value) { public String toString(NClob value) {