From a381e368eb048c7a44e5b08e0a1603190ce1e5bc Mon Sep 17 00:00:00 2001 From: Andrej Golovnin Date: Thu, 27 Nov 2014 21:01:21 +0100 Subject: [PATCH] HHH-9336 Avoid creation of TypedValue objects in AbstractPersistentCollection#getOrphans(Collection, Collection, String, SessionImplementor) for some ID types. --- .../AbstractPersistentCollection.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java index 2bb52f27bc..4162a2b964 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java @@ -55,7 +55,13 @@ import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; import org.hibernate.type.ComponentType; +import org.hibernate.type.IntegerType; +import org.hibernate.type.LongType; +import org.hibernate.type.PostgresUUIDType; +import org.hibernate.type.StringType; import org.hibernate.type.Type; +import org.hibernate.type.UUIDBinaryType; +import org.hibernate.type.UUIDCharType; import org.jboss.logging.Logger; /** @@ -1117,6 +1123,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers final EntityPersister entityPersister = session.getFactory().getEntityPersister( entityName ); final Type idType = entityPersister.getIdentifierType(); + final boolean useIdDirect = mayUseIdDirect( idType ); // create the collection holding the Orphans final Collection res = new ArrayList(); @@ -1136,7 +1143,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers current, session ); - currentIds.add( new TypedValue( idType, currentId ) ); + currentIds.add( useIdDirect ? currentId : new TypedValue( idType, currentId ) ); } } } @@ -1145,7 +1152,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers for ( Object old : oldElements ) { if ( !currentSaving.contains( old ) ) { final Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, old, session ); - if ( !currentIds.contains( new TypedValue( idType, oldId ) ) ) { + if ( !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) { res.add( old ); } } @@ -1154,6 +1161,15 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers return res; } + private static boolean mayUseIdDirect(Type idType) { + return idType == StringType.INSTANCE + || idType == IntegerType.INSTANCE + || idType == LongType.INSTANCE + || idType == UUIDBinaryType.INSTANCE + || idType == UUIDCharType.INSTANCE + || idType == PostgresUUIDType.INSTANCE; + } + /** * Removes entity entries that have an equal identifier with the incoming entity instance *