Class DataModelUtil
This class is the Hibernate 6 replacement for the pre-4.0.8 version, which reached into
CriteriaImpl, CriteriaQueryTranslator, CriteriaJoinWalker and
NamedQueryDefinition. None of those types exist any more, and the legacy Criteria API they
served has been replaced by JPA Criteria / Spring Data Specifications. Everything here is
now expressed against the JPA Metamodel.
The isNamedQuerySupported and getSqlString(Criteria) helpers were dropped: the
project no longer defines any named query, and Hibernate 6 has no Criteria to stringify
(enable the org.hibernate.SQL logger instead).
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasAttribute(jakarta.persistence.metamodel.ManagedType<?> type, String attribute) Checks whether a managed type maps an attribute of the given name.static booleanisEntitySupported(Class<?> clazz, jakarta.persistence.EntityManager entityManager) Checks whether the given entity type is mapped in the active persistence unit.static booleanisPropertyNameSupported(String property, Class<?> clazz, jakarta.persistence.EntityManager entityManager) Checks whether the given entity maps an attribute of the given name.
-
Method Details
-
isEntitySupported
public static boolean isEntitySupported(Class<?> clazz, jakarta.persistence.EntityManager entityManager) Checks whether the given entity type is mapped in the active persistence unit.- Parameters:
clazz- the entity type to look forentityManager- the entity manager whose metamodel is introspected, may benull- Returns:
trueif the type is a mapped entity
-
isPropertyNameSupported
public static boolean isPropertyNameSupported(String property, Class<?> clazz, jakarta.persistence.EntityManager entityManager) Checks whether the given entity maps an attribute of the given name.Used to decide whether hierarchical filtering (
parents/children) is available, which depends on the database-model variant in use.- Parameters:
property- the attribute name to look forclazz- the entity type owning the attributeentityManager- the entity manager whose metamodel is introspected, may benull- Returns:
trueif the attribute is mapped on that entity
-
hasAttribute
public static boolean hasAttribute(jakarta.persistence.metamodel.ManagedType<?> type, String attribute) Checks whether a managed type maps an attribute of the given name.This overload takes the metamodel type directly so it can be used from inside a
Specification, where only the queryRootis available and there is no handle on theEntityManager:root.getModel()yields theManagedTypeto pass here.- Parameters:
type- the managed type to introspect, may benullattribute- the attribute name to look for- Returns:
trueif the attribute is mapped on that type
-