diff --git a/hibernate-core/src/main/java/org/hibernate/Hibernate.java b/hibernate-core/src/main/java/org/hibernate/Hibernate.java index b961a5c5a3..b885c81680 100644 --- a/hibernate-core/src/main/java/org/hibernate/Hibernate.java +++ b/hibernate-core/src/main/java/org/hibernate/Hibernate.java @@ -186,8 +186,8 @@ public final class Hibernate { } /** - * Get the true, underlying class of a proxied persistent class. This operation - * will initialize a proxy by side effect. + * Get the true, underlying class of a proxied entity. This operation will + * initialize a proxy by side effect. * * @param proxy an entity instance or proxy * @return the true class of the instance @@ -206,6 +206,20 @@ public final class Hibernate { return (Class) result; } + /** + * Determine if the true, underlying class of the proxied entity is assignable + * to the given class. This operation will initialize a proxy by side effect. + * + * @param proxy an entity instance or proxy + * @return {@code true} if the entity is an instance of the given class + * + * @since 6.2 + */ + public static boolean isInstance(Object proxy, Class entityClass) { + return entityClass.isInstance( proxy ) + || entityClass.isAssignableFrom( getClass( proxy ) ); + } + /** * Determines if the property with the given name of the given entity instance is * initialized. If the named property does not exist or is not persistent, this