add Hibernate.isInstance() convenience method

This commit is contained in:
Gavin 2022-11-21 19:29:04 +01:00 committed by Gavin King
parent 5160ac3192
commit fae1ec40fd
1 changed files with 16 additions and 2 deletions

View File

@ -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<? extends T>) 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