public class GrailsHibernateUtil extends HibernateRuntimeUtils
Utility methods for configuring Hibernate inside Grails.
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
ARGUMENT_CACHE |
|
static java.lang.String |
ARGUMENT_FETCH |
|
static java.lang.String |
ARGUMENT_FETCH_SIZE |
|
static java.lang.String |
ARGUMENT_FLUSH_MODE |
|
static java.lang.String |
ARGUMENT_IGNORE_CASE |
|
static java.lang.String |
ARGUMENT_LOCK |
|
static java.lang.String |
ARGUMENT_MAX |
|
static java.lang.String |
ARGUMENT_OFFSET |
|
static java.lang.String |
ARGUMENT_ORDER |
|
static java.lang.String |
ARGUMENT_READ_ONLY |
|
static java.lang.String |
ARGUMENT_SORT |
|
static java.lang.String |
ARGUMENT_TIMEOUT |
|
static java.lang.Class<?>[] |
EMPTY_CLASS_ARRAY |
|
protected static org.slf4j.Logger |
LOG |
|
static java.lang.String |
ORDER_ASC |
|
static java.lang.String |
ORDER_DESC |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static void |
applyJoinType(AbstractHibernateDatastore datastore, java.lang.Class<?> targetClass, Criteria root, java.lang.String associationPath, jakarta.persistence.criteria.JoinType joinType)Applies the join type that a criteria query requests for an association, with the fetch
argument or with join(String, JoinType). |
|
public static void |
applyJoinType(PersistentEntity entity, Criteria root, java.lang.String associationPath, jakarta.persistence.criteria.JoinType joinType)Applies the join type that a query requests for an association: see applyJoinType(AbstractHibernateDatastore, Class, Criteria, String, jakarta.persistence.criteria.JoinType). |
|
public static void |
applyJoinTypeToExistingJoin(Criteria root, java.lang.String associationPath, jakarta.persistence.criteria.JoinType joinType)Applies a join type to the join that the criteria already make for an association, with an association block or an alias. |
|
public static void |
cacheCriteriaByMapping(java.lang.Class<?> targetClass, Criteria criteria)Configures the criteria instance to cache based on the configured mapping. |
|
public static void |
cacheCriteriaByMapping(AbstractHibernateDatastore datastore, java.lang.Class<?> targetClass, Criteria criteria) |
|
public static void |
ensureCorrectGroovyMetaClass(java.lang.Object target, java.lang.Class<?> persistentClass)Ensures the meta class is correct for a given class |
|
public static void |
fetchAssociationsBefore(Criteria criteria, java.lang.String associationPath)Asks the criteria to fetch, with a join, the associations before the last one on a path that a join type is requested for, unless they request another fetch mode for them. |
|
public static org.hibernate.proxy.HibernateProxy |
getAssociationProxy(java.lang.Object obj, java.lang.String associationName)Returns the proxy for a given association or null if it is not proxied |
|
public static java.util.List<java.lang.String> |
getDatasourceNames(PersistentEntity domainClass)
|
|
public static java.lang.String |
getDefaultDataSource(PersistentEntity domainClass)
|
|
public static org.hibernate.FetchMode |
getFetchMode(java.lang.Object object)Retrieves the fetch mode for the specified instance; otherwise returns the default FetchMode. |
|
public static void |
incrementVersion(java.lang.Object target)Increments the entities version number in order to force an update |
|
public static boolean |
isInitialized(java.lang.Object obj, java.lang.String associationName)Checks whether an associated property is initialized and returns true if it is |
|
public static boolean |
isLeftJoinAssociationSort(PersistentEntity entity)Whether a sort by a property of an association joins the association with a left join, so that the sort keeps the instances whose association is null. |
|
public static boolean |
isMappedWithHibernate(PersistentEntity domainClass) |
|
public static boolean |
isNotEmpty(java.lang.String string) |
|
public static Criterion |
joinedInSubquery(java.lang.String entityName, java.lang.String rootAlias, java.lang.String associationPath)Returns a restriction to the instances of an entity for which an inner join of an association path returns a row. |
|
public static void |
populateArgumentsForCriteria(AbstractHibernateDatastore datastore, java.lang.Class<?> targetClass, Criteria c, java.util.Map argMap, org.springframework.core.convert.ConversionService conversionService) |
|
public static void |
populateArgumentsForCriteria(AbstractHibernateDatastore datastore, java.lang.Class<?> targetClass, Criteria c, java.util.Map argMap, org.springframework.core.convert.ConversionService conversionService, boolean useDefaultMapping)Populates criteria arguments for the given target class and arguments map |
|
public static void |
populateArgumentsForCriteria(java.lang.Class<?> targetClass, Criteria c, java.util.Map argMap, org.springframework.core.convert.ConversionService conversionService)Populates criteria arguments for the given target class and arguments map |
|
public static void |
populateArgumentsForCriteria(Criteria c, java.util.Map argMap, org.springframework.core.convert.ConversionService conversionService) |
|
public static java.lang.String |
qualify(java.lang.String prefix, java.lang.String name) |
|
public static void |
setBinder(GrailsDomainBinder binder)
|
|
public static void |
setObjectToReadWrite(java.lang.Object target, org.hibernate.SessionFactory sessionFactory)Sets the target object to read-write, allowing Hibernate to dirty check it and auto-flush changes. |
|
public static void |
setObjectToReadyOnly(java.lang.Object target, org.hibernate.SessionFactory sessionFactory)Sets the target object to read-only using the given SessionFactory instance. |
|
public static java.lang.String |
unqualify(java.lang.String qualifiedName) |
|
public static java.lang.Object |
unwrapIfProxy(java.lang.Object instance)Unproxies a HibernateProxy. |
|
public static java.lang.Object |
unwrapProxy(org.hibernate.proxy.HibernateProxy proxy)Unwraps and initializes a HibernateProxy. |
|
public static boolean |
usesDatasource(PersistentEntity domainClass, java.lang.String dataSourceName)
|
| Methods inherited from class | Name |
|---|---|
class HibernateRuntimeUtils |
autoAssociateBidirectionalOneToOnes, convertValueToType, enableDynamicFilterEnablerIfPresent, setupErrorsProperty |
Applies the join type that a criteria query requests for an association, with the fetch
argument or with join(String, JoinType). The association is fetched, as it is for the
'join' fetch mode. A fetch mode alone always joins with an outer join, so a join type
is applied to the existing join of the association as well as to a new join.
Hibernate fetches a collection only through a left join, and a join through a collection returns an instance once for each element of the collection. A path that ends in a collection, or passes through one, that the criteria do not join is therefore joined in a subquery, see joinedInSubquery(String, String, String). A collection at the end of the path keeps the left join of the fetch mode, and the associations before it are joined, so that the collection is fetched.
datastore - The datastoretargetClass - The class that the criteria queryroot - The root criteriaassociationPath - The path of the association from the target classjoinType - The requested join typeApplies the join type that a query requests for an association: see applyJoinType(AbstractHibernateDatastore, Class, Criteria, String, jakarta.persistence.criteria.JoinType).
entity - The entity that the criteria queryroot - The root criteriaassociationPath - The path of the association from the entityjoinType - The requested join typeApplies a join type to the join that the criteria already make for an association, with an association block or an alias. The join is made again with the join type, under the same alias, so that the criteria that use the alias use the join type. Nothing is joined when the criteria make no join for the association.
root - The root criteriaassociationPath - The path of the association from the root entityjoinType - The join typeConfigures the criteria instance to cache based on the configured mapping.
targetClass - The target classcriteria - The criteriaEnsures the meta class is correct for a given class
target - The GroovyObjectpersistentClass - The persistent classAsks the criteria to fetch, with a join, the associations before the last one on a path that a join type is requested for, unless they request another fetch mode for them. Hibernate fetches an association by its fetch mode only when it fetches the associations before it, and a collection on the path is fetched with all of its elements, since nothing restricts them: the requested join type only decides which instances the query returns.
criteria - The criteria of the queryassociationPath - The path from the root entityReturns the proxy for a given association or null if it is not proxied
obj - The objectassociationName - The named assoicationRetrieves the fetch mode for the specified instance; otherwise returns the default FetchMode.
object - The object, converted to a stringIncrements the entities version number in order to force an update
target - The target entityChecks whether an associated property is initialized and returns true if it is
obj - The name of the objectassociationName - The name of the association Whether a sort by a property of an association joins the association with a left join, so that the
sort keeps the instances whose association is null. That is the case when the
grails.gorm.leftJoinAssociationSort setting is enabled. The association is otherwise
joined with an inner join.
entity - an entity of the datastore that runs the queryReturns a restriction to the instances of an entity for which an inner join of an association path returns a row. The path is joined in a subquery, which is correlated with the query by the identifier of the entity.
A join through a collection returns an instance once for each element of the collection. That multiplies the rows that a row limit and a count work on, and a collection that is fetched from those rows lacks the elements that the rest of the path leaves out. A subquery restricts the query to the same instances without either effect. Unlike a check that a collection is not empty, its joins apply the filters that are enabled for the session, such as the one of discriminator based multi-tenancy.
entityName - The name of the entity that the query returnsrootAlias - The alias of the root of the queryassociationPath - The path of the association from the entityPopulates criteria arguments for the given target class and arguments map
datastore - the GrailsApplication instancetargetClass - The target classc - The criteria instanceargMap - The arguments mapPopulates criteria arguments for the given target class and arguments map
targetClass - The target classc - The criteria instanceargMap - The arguments mapSets the target object to read-write, allowing Hibernate to dirty check it and auto-flush changes.
target - The target objectsessionFactory - The SessionFactory instanceSets the target object to read-only using the given SessionFactory instance. This avoids Hibernate performing any dirty checking on the object
target - The target objectsessionFactory - The SessionFactory instanceUnproxies a HibernateProxy. If the proxy is uninitialized, it automatically triggers an initialization. In case the supplied object is null or not a proxy, the object will be returned as-is.
Unwraps and initializes a HibernateProxy.
proxy - The proxy