From ec72bab0a9d416d3e3c71ff90b8d2487f35966b4 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 26 Oct 2022 14:02:43 +0200 Subject: [PATCH] HHH-15633 Intern entity name to improve EntityKey#equals --- .../src/main/java/org/hibernate/engine/spi/EntityKey.java | 3 +-- .../java/org/hibernate/tuple/entity/EntityMetamodel.java | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityKey.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityKey.java index d60d5967ba..ec79528302 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityKey.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/EntityKey.java @@ -10,7 +10,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import java.util.Objects; import org.hibernate.AssertionFailure; import org.hibernate.persister.entity.EntityPersister; @@ -103,7 +102,7 @@ public final class EntityKey implements Serializable { private boolean samePersistentType(final EntityKey otherKey) { return otherKey.persister == persister - || Objects.equals( otherKey.persister.getRootEntityName(), persister.getRootEntityName() ); + || otherKey.persister.getRootEntityName().equals( persister.getRootEntityName() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index d7bd34d132..6e3ecdcf92 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -147,8 +147,9 @@ public class EntityMetamodel implements Serializable { RuntimeModelCreationContext creationContext) { this.sessionFactory = creationContext.getSessionFactory(); - name = persistentClass.getEntityName(); - rootName = persistentClass.getRootClass().getEntityName(); + // Improves performance of EntityKey#equals by avoiding content check in String#equals + name = persistentClass.getEntityName().intern(); + rootName = persistentClass.getRootClass().getEntityName().intern(); identifierAttribute = PropertyFactory.buildIdentifierAttribute( persistentClass,