Package org.hibernate.criterion
Class DetachedCriteria
- java.lang.Object
-
- org.hibernate.criterion.DetachedCriteria
-
- All Implemented Interfaces:
java.io.Serializable,CriteriaSpecification
public class DetachedCriteria extends java.lang.Object implements CriteriaSpecification, java.io.Serializable
Models a detached form of a Criteria (not associated with a Session). Some applications need to create criteria queries in "detached mode", where the Hibernate Session is not available. Applications would create a DetachableCriteria to describe the query, and then later associated it with a Session to obtain the "executable" Criteria:DetachedCriteria detached = new DetachedCriteria(); ... Criteria criteria = detached.getExecutableCriteria( session ); ... criteria.list();All methods have the same semantics and behavior as the corresponding methods of the Criteria interface.- See Also:
Criteria, Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.hibernate.criterion.CriteriaSpecification
ALIAS_TO_ENTITY_MAP, DISTINCT_ROOT_ENTITY, FULL_JOIN, INNER_JOIN, LEFT_JOIN, PROJECTION, ROOT_ALIAS, ROOT_ENTITY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDetachedCriteria(java.lang.String entityName)protectedDetachedCriteria(java.lang.String entityName, java.lang.String alias)protectedDetachedCriteria(org.hibernate.internal.CriteriaImpl impl, Criteria criteria)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DetachedCriteriaadd(Criterion criterion)Add a restrictionDetachedCriteriaaddOrder(Order order)Adds an orderingDetachedCriteriacreateAlias(java.lang.String associationPath, java.lang.String alias)Creates an association path alias within this DetachedCriteria.DetachedCriteriacreateAlias(java.lang.String associationPath, java.lang.String alias, int joinType)Deprecated.DetachedCriteriacreateAlias(java.lang.String associationPath, java.lang.String alias, int joinType, Criterion withClause)Deprecated.DetachedCriteriacreateAlias(java.lang.String associationPath, java.lang.String alias, JoinType joinType)Creates an association path alias within this DetachedCriteria specifying the type of join.DetachedCriteriacreateAlias(java.lang.String associationPath, java.lang.String alias, JoinType joinType, Criterion withClause)Creates an association path alias within this DetachedCriteria specifying the type of join.DetachedCriteriacreateCriteria(java.lang.String associationPath)Creates a nested DetachedCriteria representing the association path.DetachedCriteriacreateCriteria(java.lang.String associationPath, int joinType)Deprecated.DetachedCriteriacreateCriteria(java.lang.String associationPath, java.lang.String alias)Creates a nested DetachedCriteria representing the association path.DetachedCriteriacreateCriteria(java.lang.String associationPath, java.lang.String alias, int joinType)Deprecated.DetachedCriteriacreateCriteria(java.lang.String associationPath, java.lang.String alias, int joinType, Criterion withClause)Deprecated.DetachedCriteriacreateCriteria(java.lang.String associationPath, java.lang.String alias, JoinType joinType)Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.DetachedCriteriacreateCriteria(java.lang.String associationPath, java.lang.String alias, JoinType joinType, Criterion withClause)Creates a nested DetachedCriteria representing the association path, specifying the type of join to use and an additional join restriction.DetachedCriteriacreateCriteria(java.lang.String associationPath, JoinType joinType)Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.static DetachedCriteriaforClass(java.lang.Class clazz)Static builder to create a DetachedCriteria for the given entity, by its Class.static DetachedCriteriaforClass(java.lang.Class clazz, java.lang.String alias)Static builder to create a DetachedCriteria for the given entity, by its Class.static DetachedCriteriaforEntityName(java.lang.String entityName)Static builder to create a DetachedCriteria for the given entity.static DetachedCriteriaforEntityName(java.lang.String entityName, java.lang.String alias)Static builder to create a DetachedCriteria for the given entity.java.lang.StringgetAlias()Obtain the alias associated with this DetachedCriteriaCriteriagetExecutableCriteria(Session session)Get an executable instance of Criteria to actually run the query.DetachedCriteriasetComment(java.lang.String comment)Set the SQL comment to use.DetachedCriteriasetFetchMode(java.lang.String associationPath, FetchMode mode)Set the fetch mode for a given associationDetachedCriteriasetLockMode(java.lang.String alias, LockMode lockMode)Set an alias-specific lock mode.DetachedCriteriasetLockMode(LockMode lockMode)Set the lock mode to use.DetachedCriteriasetProjection(Projection projection)Set the projection to use.DetachedCriteriasetResultTransformer(ResultTransformer resultTransformer)Set the result transformer to use.DetachedCriteriasetTimeout(int timeout)Set a timeout for the underlying JDBC query.java.lang.StringtoString()
-
-
-
Constructor Detail
-
DetachedCriteria
protected DetachedCriteria(java.lang.String entityName)
-
DetachedCriteria
protected DetachedCriteria(java.lang.String entityName, java.lang.String alias)
-
DetachedCriteria
protected DetachedCriteria(org.hibernate.internal.CriteriaImpl impl, Criteria criteria)
-
-
Method Detail
-
getExecutableCriteria
public Criteria getExecutableCriteria(Session session)
Get an executable instance of Criteria to actually run the query.- Parameters:
session- The session to associate the built Criteria with- Returns:
- The "executable" Criteria
-
getAlias
public java.lang.String getAlias()
Obtain the alias associated with this DetachedCriteria- Returns:
- The alias
-
forEntityName
public static DetachedCriteria forEntityName(java.lang.String entityName)
Static builder to create a DetachedCriteria for the given entity.- Parameters:
entityName- The name of the entity to create a DetachedCriteria for- Returns:
- The DetachedCriteria
-
forEntityName
public static DetachedCriteria forEntityName(java.lang.String entityName, java.lang.String alias)
Static builder to create a DetachedCriteria for the given entity.- Parameters:
entityName- The name of the entity to create a DetachedCriteria foralias- The alias to apply to the entity- Returns:
- The DetachedCriteria
-
forClass
public static DetachedCriteria forClass(java.lang.Class clazz)
Static builder to create a DetachedCriteria for the given entity, by its Class.- Parameters:
clazz- The entity class- Returns:
- The DetachedCriteria
-
forClass
public static DetachedCriteria forClass(java.lang.Class clazz, java.lang.String alias)
Static builder to create a DetachedCriteria for the given entity, by its Class.- Parameters:
clazz- The entity classalias- The alias to apply to the entity- Returns:
- The DetachedCriteria
-
add
public DetachedCriteria add(Criterion criterion)
Add a restriction- Parameters:
criterion- The restriction- Returns:
this, for method chaining
-
addOrder
public DetachedCriteria addOrder(Order order)
Adds an ordering- Parameters:
order- The ordering- Returns:
this, for method chaining
-
setFetchMode
public DetachedCriteria setFetchMode(java.lang.String associationPath, FetchMode mode)
Set the fetch mode for a given association- Parameters:
associationPath- The association pathmode- The fetch mode to apply- Returns:
this, for method chaining
-
setProjection
public DetachedCriteria setProjection(Projection projection)
Set the projection to use.- Parameters:
projection- The projection to use- Returns:
this, for method chaining
-
setResultTransformer
public DetachedCriteria setResultTransformer(ResultTransformer resultTransformer)
Set the result transformer to use.- Parameters:
resultTransformer- The result transformer to use- Returns:
this, for method chaining
-
createAlias
public DetachedCriteria createAlias(java.lang.String associationPath, java.lang.String alias)
Creates an association path alias within this DetachedCriteria. The alias can then be used in further alias creations or restrictions, etc.- Parameters:
associationPath- The association pathalias- The alias to apply to that association path- Returns:
this, for method chaining
-
createAlias
public DetachedCriteria createAlias(java.lang.String associationPath, java.lang.String alias, JoinType joinType)
Creates an association path alias within this DetachedCriteria specifying the type of join. The alias can then be used in further alias creations or restrictions, etc.- Parameters:
associationPath- The association pathalias- The alias to apply to that association pathjoinType- The type of join to use- Returns:
this, for method chaining
-
createAlias
public DetachedCriteria createAlias(java.lang.String associationPath, java.lang.String alias, JoinType joinType, Criterion withClause)
Creates an association path alias within this DetachedCriteria specifying the type of join. The alias can then be used in further alias creations or restrictions, etc.- Parameters:
associationPath- The association pathalias- The alias to apply to that association pathjoinType- The type of join to usewithClause- An additional restriction on the join- Returns:
this, for method chaining
-
createAlias
@Deprecated public DetachedCriteria createAlias(java.lang.String associationPath, java.lang.String alias, int joinType)
Deprecated.Deprecated!- Parameters:
associationPath- The association pathalias- The alias to apply to that association pathjoinType- The type of join to use- Returns:
this, for method chaining
-
createAlias
@Deprecated public DetachedCriteria createAlias(java.lang.String associationPath, java.lang.String alias, int joinType, Criterion withClause)
Deprecated.Deprecated!- Parameters:
associationPath- The association pathalias- The alias to apply to that association pathjoinType- The type of join to usewithClause- An additional restriction on the join- Returns:
this, for method chaining
-
createCriteria
public DetachedCriteria createCriteria(java.lang.String associationPath, java.lang.String alias)
Creates a nested DetachedCriteria representing the association path.- Parameters:
associationPath- The association pathalias- The alias to apply to that association path- Returns:
- the newly created, nested DetachedCriteria
-
createCriteria
public DetachedCriteria createCriteria(java.lang.String associationPath)
Creates a nested DetachedCriteria representing the association path.- Parameters:
associationPath- The association path- Returns:
- the newly created, nested DetachedCriteria
-
createCriteria
public DetachedCriteria createCriteria(java.lang.String associationPath, JoinType joinType)
Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.- Parameters:
associationPath- The association pathjoinType- The type of join to use- Returns:
- the newly created, nested DetachedCriteria
-
createCriteria
public DetachedCriteria createCriteria(java.lang.String associationPath, java.lang.String alias, JoinType joinType)
Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.- Parameters:
associationPath- The association pathalias- The alias to associate with this "join".joinType- The type of join to use- Returns:
- the newly created, nested DetachedCriteria
-
createCriteria
public DetachedCriteria createCriteria(java.lang.String associationPath, java.lang.String alias, JoinType joinType, Criterion withClause)
Creates a nested DetachedCriteria representing the association path, specifying the type of join to use and an additional join restriction.- Parameters:
associationPath- The association pathalias- The alias to associate with this "join".joinType- The type of join to usewithClause- The additional join restriction- Returns:
- the newly created, nested DetachedCriteria
-
createCriteria
@Deprecated public DetachedCriteria createCriteria(java.lang.String associationPath, int joinType)
Deprecated.Deprecated!- Parameters:
associationPath- The association pathjoinType- The type of join to use- Returns:
- the newly created, nested DetachedCriteria
-
createCriteria
@Deprecated public DetachedCriteria createCriteria(java.lang.String associationPath, java.lang.String alias, int joinType)
Deprecated.Deprecated!- Parameters:
associationPath- The association pathalias- The aliasjoinType- The type of join to use- Returns:
- the newly created, nested DetachedCriteria
-
createCriteria
@Deprecated public DetachedCriteria createCriteria(java.lang.String associationPath, java.lang.String alias, int joinType, Criterion withClause)
Deprecated.Deprecated!- Parameters:
associationPath- The association pathalias- The alias to associate with this "join".joinType- The type of join to usewithClause- The additional join restriction- Returns:
- the newly created, nested DetachedCriteria
-
setComment
public DetachedCriteria setComment(java.lang.String comment)
Set the SQL comment to use.- Parameters:
comment- The SQL comment to use- Returns:
this, for method chaining
-
setLockMode
public DetachedCriteria setLockMode(LockMode lockMode)
Set the lock mode to use.- Parameters:
lockMode- The lock mode to use- Returns:
this, for method chaining
-
setLockMode
public DetachedCriteria setLockMode(java.lang.String alias, LockMode lockMode)
Set an alias-specific lock mode. The specified lock mode applies only to that alias.- Parameters:
alias- The alias to apply the lock tolockMode- The lock mode to use.- Returns:
this, for method chaining
-
setTimeout
public DetachedCriteria setTimeout(int timeout)
Set a timeout for the underlying JDBC query.- Parameters:
timeout- The timeout value to apply.- Returns:
- this (for method chaining)
- See Also:
Statement.setQueryTimeout(int)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-