Top Description Fields Constructors Methods
org.hibernate.criterion

public Class DetachedCriteria

extends Object
implements CriteriaSpecification, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.hibernate.criterion.CriteriaSpecification
Imports
java.io.Serializable, org.hibernate.Criteria, .FetchMode, .LockMode, .Session, org.hibernate.engine.spi.SessionImplementor, org.hibernate.internal.CriteriaImpl, org.hibernate.sql.JoinType, org.hibernate.transform.ResultTransformer

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.
Author
Gavin King
See Also
org.hibernate.Criteria

Field Summary

Modifier and TypeField and Description
private final Criteria
private final CriteriaImpl

Constructor Summary

AccessConstructor and Description
protected
protected
DetachedCriteria(String entityName, String alias)

protected

Method Summary

Modifier and TypeMethod and Description
public DetachedCriteria

Returns:

this, for method chaining
add
(Criterion
The restriction
criterion
)

Add a restriction

public DetachedCriteria

Returns:

this, for method chaining
addOrder
(Order
The ordering
order
)

Adds an ordering

public DetachedCriteria

Returns:

this, for method chaining
createAlias
(String
The association path
associationPath
,
String
The alias to apply to that association path
alias
)

Creates an association path alias within this DetachedCriteria.

public DetachedCriteria

Returns:

this, for method chaining
createAlias
(String
The association path
associationPath
,
String
The alias to apply to that association path
alias
,
JoinType
The type of join to use
joinType
)

Creates an association path alias within this DetachedCriteria specifying the type of join.

public DetachedCriteria

Returns:

this, for method chaining
createAlias
(String
The association path
associationPath
,
String
The alias to apply to that association path
alias
,
JoinType
The type of join to use
joinType
,
Criterion
An additional restriction on the join
withClause
)

Creates an association path alias within this DetachedCriteria specifying the type of join.

public DetachedCriteria

Returns:

this, for method chaining
createAlias
(String
The association path
associationPath
,
String
The alias to apply to that association path
alias
,
int
The type of join to use
joinType
)

Deprecated!
public DetachedCriteria

Returns:

this, for method chaining
createAlias
(String
The association path
associationPath
,
String
The alias to apply to that association path
alias
,
int
The type of join to use
joinType
,
Criterion
An additional restriction on the join
withClause
)

Deprecated!
public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
,
String
The alias to apply to that association path
alias
)

Creates a nested DetachedCriteria representing the association path.

public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
)

Creates a nested DetachedCriteria representing the association path.

public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
,
JoinType
The type of join to use
joinType
)

Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.

public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
,
String
The alias to associate with this "join".
alias
,
JoinType
The type of join to use
joinType
)

Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.

public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
,
String
The alias to associate with this "join".
alias
,
JoinType
The type of join to use
joinType
,
Criterion
The additional join restriction
withClause
)

Creates a nested DetachedCriteria representing the association path, specifying the type of join to use and an additional join restriction.

public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
,
int
The type of join to use
joinType
)

Deprecated!
public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
,
String
The alias
alias
,
int
The type of join to use
joinType
)

Deprecated!
public DetachedCriteria

Returns:

the newly created, nested DetachedCriteria
createCriteria
(String
The association path
associationPath
,
String
The alias to associate with this "join".
alias
,
int
The type of join to use
joinType
,
Criterion
The additional join restriction
withClause
)

Deprecated!
public static DetachedCriteria

Returns:

The DetachedCriteria
forClass
(Class<T>
The entity class
clazz
)

Static builder to create a DetachedCriteria for the given entity, by its Class.

public static DetachedCriteria

Returns:

The DetachedCriteria
forClass
(Class<T>
The entity class
clazz
,
String
The alias to apply to the entity
alias
)

Static builder to create a DetachedCriteria for the given entity, by its Class.

public static DetachedCriteria

Returns:

The DetachedCriteria
forEntityName
(String
The name of the entity to create a DetachedCriteria for
entityName
)

Static builder to create a DetachedCriteria for the given entity.

public static DetachedCriteria

Returns:

The DetachedCriteria
forEntityName
(String
The name of the entity to create a DetachedCriteria for
entityName
,
String
The alias to apply to the entity
alias
)

Static builder to create a DetachedCriteria for the given entity.

public String

Returns:

The alias
getAlias
()

Obtain the alias associated with this DetachedCriteria

pack-priv CriteriaImpl

Returns:

The internally maintained CriteriaImpl
getCriteriaImpl
()

Retrieve the CriteriaImpl used internally to hold the DetachedCriteria state

public Criteria

Returns:

The "executable" Criteria
getExecutableCriteria
(Session
The session to associate the built Criteria with
session
)

Deprecated as a consequence of Session being deprecated.
Get an executable instance of Criteria to actually run the query.
public DetachedCriteria

Returns:

this, for method chaining
setComment
(String
The SQL comment to use
comment
)

Set the SQL comment to use.

public DetachedCriteria

Returns:

this, for method chaining
setFetchMode
(String
The association path
associationPath
,
FetchMode
The fetch mode to apply
mode
)

Set the fetch mode for a given association

public DetachedCriteria

Returns:

this, for method chaining
setLockMode
(LockMode
The lock mode to use
lockMode
)

Set the lock mode to use.

public DetachedCriteria

Returns:

this, for method chaining
setLockMode
(String
The alias to apply the lock to
alias
,
LockMode
The lock mode to use.
lockMode
)

Set an alias-specific lock mode.

public DetachedCriteria

Returns:

this, for method chaining
setProjection
(Projection
The projection to use
projection
)

Set the projection to use.

public DetachedCriteria

Returns:

this, for method chaining
setResultTransformer
(ResultTransformer
The result transformer to use
resultTransformer
)

Set the result transformer to use.

public DetachedCriteria

Returns:

this (for method chaining)
setTimeout
(int
The timeout value to apply.
timeout
)

Set a timeout for the underlying JDBC query.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

criteriaback to summary
private final Criteria criteria
implback to summary
private final CriteriaImpl impl

Constructor Detail

DetachedCriteriaback to summary
protected DetachedCriteria(String entityName)
DetachedCriteriaback to summary
protected DetachedCriteria(String entityName, String alias)
DetachedCriteriaback to summary
protected DetachedCriteria(CriteriaImpl impl, Criteria criteria)

Method Detail

addback to summary
public DetachedCriteria add(Criterion criterion)

Add a restriction

Parameters
criterion:Criterion

The restriction

Returns:DetachedCriteria

this, for method chaining

addOrderback to summary
public DetachedCriteria addOrder(Order order)

Adds an ordering

Parameters
order:Order

The ordering

Returns:DetachedCriteria

this, for method chaining

createAliasback to summary
public DetachedCriteria createAlias(String associationPath, 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:String

The association path

alias:String

The alias to apply to that association path

Returns:DetachedCriteria

this, for method chaining

createAliasback to summary
public DetachedCriteria createAlias(String associationPath, 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:String

The association path

alias:String

The alias to apply to that association path

joinType:JoinType

The type of join to use

Returns:DetachedCriteria

this, for method chaining

createAliasback to summary
public DetachedCriteria createAlias(String associationPath, 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:String

The association path

alias:String

The alias to apply to that association path

joinType:JoinType

The type of join to use

withClause:Criterion

An additional restriction on the join

Returns:DetachedCriteria

this, for method chaining

createAliasback to summary
public DetachedCriteria createAlias(String associationPath, String alias, int joinType)

Deprecated!

Parameters
associationPath:String

The association path

alias:String

The alias to apply to that association path

joinType:int

The type of join to use

Returns:DetachedCriteria

this, for method chaining

Annotations
@Deprecated
createAliasback to summary
public DetachedCriteria createAlias(String associationPath, String alias, int joinType, Criterion withClause)

Deprecated!

Parameters
associationPath:String

The association path

alias:String

The alias to apply to that association path

joinType:int

The type of join to use

withClause:Criterion

An additional restriction on the join

Returns:DetachedCriteria

this, for method chaining

Annotations
@Deprecated
createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath, String alias)

Creates a nested DetachedCriteria representing the association path.

Parameters
associationPath:String

The association path

alias:String

The alias to apply to that association path

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath)

Creates a nested DetachedCriteria representing the association path.

Parameters
associationPath:String

The association path

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath, JoinType joinType)

Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.

Parameters
associationPath:String

The association path

joinType:JoinType

The type of join to use

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath, String alias, JoinType joinType)

Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.

Parameters
associationPath:String

The association path

alias:String

The alias to associate with this "join".

joinType:JoinType

The type of join to use

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath, 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:String

The association path

alias:String

The alias to associate with this "join".

joinType:JoinType

The type of join to use

withClause:Criterion

The additional join restriction

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath, int joinType)

Deprecated!

Parameters
associationPath:String

The association path

joinType:int

The type of join to use

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

Annotations
@Deprecated
createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType)

Deprecated!

Parameters
associationPath:String

The association path

alias:String

The alias

joinType:int

The type of join to use

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

Annotations
@Deprecated
createCriteriaback to summary
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause)

Deprecated!

Parameters
associationPath:String

The association path

alias:String

The alias to associate with this "join".

joinType:int

The type of join to use

withClause:Criterion

The additional join restriction

Returns:DetachedCriteria

the newly created, nested DetachedCriteria

Annotations
@Deprecated
forClassback to summary
public static DetachedCriteria forClass(Class<T> clazz)

Static builder to create a DetachedCriteria for the given entity, by its Class.

Parameters
clazz:Class<T>

The entity class

Returns:DetachedCriteria

The DetachedCriteria

forClassback to summary
public static DetachedCriteria forClass(Class<T> clazz, String alias)

Static builder to create a DetachedCriteria for the given entity, by its Class.

Parameters
clazz:Class<T>

The entity class

alias:String

The alias to apply to the entity

Returns:DetachedCriteria

The DetachedCriteria

forEntityNameback to summary
public static DetachedCriteria forEntityName(String entityName)

Static builder to create a DetachedCriteria for the given entity.

Parameters
entityName:String

The name of the entity to create a DetachedCriteria for

Returns:DetachedCriteria

The DetachedCriteria

Annotations
@SuppressWarnings:UnusedDeclaration
forEntityNameback to summary
public static DetachedCriteria forEntityName(String entityName, String alias)

Static builder to create a DetachedCriteria for the given entity.

Parameters
entityName:String

The name of the entity to create a DetachedCriteria for

alias:String

The alias to apply to the entity

Returns:DetachedCriteria

The DetachedCriteria

Annotations
@SuppressWarnings:UnusedDeclaration
getAliasback to summary
public String getAlias()

Obtain the alias associated with this DetachedCriteria

Returns:String

The alias

getCriteriaImplback to summary
pack-priv CriteriaImpl getCriteriaImpl()

Retrieve the CriteriaImpl used internally to hold the DetachedCriteria state

Returns:CriteriaImpl

The internally maintained CriteriaImpl

getExecutableCriteriaback to summary
public Criteria getExecutableCriteria(Session session)

Deprecated

as a consequence of Session being deprecated. See corresponding docs for further information.

Get an executable instance of Criteria to actually run the query.

Parameters
session:Session

The session to associate the built Criteria with

Returns:Criteria

The "executable" Criteria

setCommentback to summary
public DetachedCriteria setComment(String comment)

Set the SQL comment to use.

Parameters
comment:String

The SQL comment to use

Returns:DetachedCriteria

this, for method chaining

setFetchModeback to summary
public DetachedCriteria setFetchMode(String associationPath, FetchMode mode)

Set the fetch mode for a given association

Parameters
associationPath:String

The association path

mode:FetchMode

The fetch mode to apply

Returns:DetachedCriteria

this, for method chaining

setLockModeback to summary
public DetachedCriteria setLockMode(LockMode lockMode)

Set the lock mode to use.

Parameters
lockMode:LockMode

The lock mode to use

Returns:DetachedCriteria

this, for method chaining

setLockModeback to summary
public DetachedCriteria setLockMode(String alias, LockMode lockMode)

Set an alias-specific lock mode. The specified lock mode applies only to that alias.

Parameters
alias:String

The alias to apply the lock to

lockMode:LockMode

The lock mode to use.

Returns:DetachedCriteria

this, for method chaining

setProjectionback to summary
public DetachedCriteria setProjection(Projection projection)

Set the projection to use.

Parameters
projection:Projection

The projection to use

Returns:DetachedCriteria

this, for method chaining

setResultTransformerback to summary
public DetachedCriteria setResultTransformer(ResultTransformer resultTransformer)

Set the result transformer to use.

Parameters
resultTransformer:ResultTransformer

The result transformer to use

Returns:DetachedCriteria

this, for method chaining

setTimeoutback to summary
public DetachedCriteria setTimeout(int timeout)

Set a timeout for the underlying JDBC query.

Parameters
timeout:int

The timeout value to apply.

Returns:DetachedCriteria

this (for method chaining)

See Also
java.sql.Statement#setQueryTimeout
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override