List cats = session.createCriteria(Cat.class)
.add( Restrictions.like("name", "Iz%") )
.add( Restrictions.gt( "weight", new Float(minWeight) ) )
.addOrder( Order.asc("age") )
.list();
You may navigate associations using createAlias() or
createCriteria().
List cats = session.createCriteria(Cat.class)
.createCriteria("kittens")
.add( Restrictions.like("name", "Iz%") )
.list();
List cats = session.createCriteria(Cat.class)
.createAlias("kittens", "kit")
.add( Restrictions.like("kit.name", "Iz%") )
.list();
You may specify projection and aggregation using Projection
instances obtained via the factory methods on Projections.
List cats = session.createCriteria(Cat.class)
.setProjection( Projections.projectionList()
.add( Projections.rowCount() )
.add( Projections.avg("weight") )
.add( Projections.max("weight") )
.add( Projections.min("weight") )
.add( Projections.groupProperty("color") )
)
.addOrder( Order.asc("color") )
.list();
Session#createCriteria(java.lang.Class) , org.hibernate.criterion.Restrictions , org.hibernate.criterion.Projections , org.hibernate.criterion.Order , org.hibernate.criterion.Criterion , org.hibernate.criterion.Projection , a disconnected version of this API
| Modifier and Type | Method and Description |
|---|---|
| public Criteria | Returns: this (for method chaining)The criterion)criterion object representing the
restriction to be applied.Add a |
| public Criteria | |
| public Criteria | Returns: this (for method chaining)The database specific query hint to add. hint)Add a DB query hint to the SQL. |
| public Criteria | Returns: this (for method chaining)A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias)Join an association, assigning an alias to the joined association. |
| public Criteria | Returns: this (for method chaining)A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, JoinType The type of join to use. joinType)Join an association using the specified join-type, assigning an alias to the joined association. |
| public Criteria | Returns: this (for method chaining)A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, int The type of join to use. joinType)
Deprecated
use
Join an association using the specified join-type, assigning an alias
to the joined association.
createAlias(String, String, org.
|
| public Criteria | Returns: this (for method chaining)A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, JoinType The type of join to use. joinType, Criterion The criteria to be added to the join condition (ON clause) withClause)Join an association using the specified join-type, assigning an alias to the joined association. |
| public Criteria | Returns: this (for method chaining)A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, int The type of join to use. joinType, Criterion The criteria to be added to the join condition (ON clause) withClause)
Deprecated
use
Join an association using the specified join-type, assigning an alias
to the joined association.
createAlias(String, String, JoinType, Criterion)
|
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath)Create a new Criteria, "rooted" at the associated entity. |
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath, JoinType The type of join to use. joinType)Create a new Criteria, "rooted" at the associated entity, using the specified join type. |
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath, int The type of join to use. joinType)
Deprecated
use
Create a new Criteria, "rooted" at the associated entity, using the
specified join type.
createAlias(String, String, org.
|
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias)Create a new Criteria, "rooted" at the associated entity, assigning the given alias. |
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, JoinType The type of join to use. joinType)Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type. |
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, int The type of join to use. joinType)
Deprecated
use
Create a new Criteria, "rooted" at the associated entity,
assigning the given alias and using the specified join type.
createCriteria(String, org.
|
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, JoinType The type of join to use. joinType, Criterion The criteria to be added to the join condition (ON clause) withClause)Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type. |
| public Criteria | Returns: the created "sub criteria"A dot-separated property path associationPath, String The alias to assign to the joined association (for later reference). alias, int The type of join to use. joinType, Criterion The criteria to be added to the join condition (ON clause) withClause)
Create a new Criteria, "rooted" at the associated entity,
assigning the given alias and using the specified join type.
|
| public String | Returns: The alias for the encapsulated entity.Get the alias of the entity encapsulated by this criteria instance. |
| public boolean | Returns: true, entities and proxies loaded by the criteria will be put in read-only mode false, entities and proxies loaded by the criteria will be put in modifiable modeShould entities and proxies loaded by this Criteria be put in read-only mode? |
| public boolean | Returns: true, the read-only/modifiable mode was explicitly initialized; false, otherwise.Was the read-only/modifiable mode explicitly initialized? |
| public List | |
| public ScrollableResults | Returns: TheScrollableResults representing the matched
query results.Get the results as an instance of |
| public ScrollableResults | Returns: TheScrollableResults representing the matched
query results.Indicates the type of underlying database cursor to
request. scrollMode)Get the results as an instance of |
| public Criteria | Returns: this (for method chaining)Should the result be considered cacheable; default is
to not cache (false). cacheable)Enable caching of this query result, provided query caching is enabled for the underlying session factory. |
| public Criteria | Returns: this (for method chaining)The cache mode to use. cacheMode)Override the cache mode for this particular query. |
| public Criteria | Returns: this (for method chaining)the name of a query cache region, or null
for the default query cache cacheRegion)Set the name of the cache region to use for query result caching. |
| public Criteria | Returns: this (for method chaining)a human-readable string comment)Add a comment to the generated SQL. |
| public Criteria | Returns: this (for method chaining)a dot separated property path associationPath, FetchMode The fetch mode for the referenced association mode)Specify an association fetching strategy for an association or a collection of values. |
| public Criteria | Returns: this (for method chaining)the fetch size fetchSize)Set a fetch size for the underlying JDBC query. |
| public Criteria | Returns: this (for method chaining)the first result to retrieve, numbered from 0 firstResult)Set the first result to be retrieved. |
| public Criteria | Returns: this (for method chaining)The flush mode to use. flushMode)Override the flush mode for this particular query. |
| public Criteria | Returns: this (for method chaining)The lock mode to be applied lockMode)Set the lock mode of the current entity. |
| public Criteria | Returns: this (for method chaining)The previously assigned alias representing the entity to
which the given lock mode should apply. alias, LockMode The lock mode to be applied lockMode)Set the lock mode of the aliased entity. |
| public Criteria | Returns: this (for method chaining)the maximum number of results maxResults)Set a limit upon the number of objects to be retrieved. |
| public Criteria | Returns: this (for method chaining)The projection representing the overall "shape" of the
query results. projection)Used to specify that the query results will be a projection (scalar in nature). |
| public Criteria | Returns: this, for method chainingtrue, entities and proxies loaded by the criteria will be put in read-only mode
false, entities and proxies loaded by the criteria will be put in modifiable mode readOnly)Set the read-only/modifiable mode for entities and proxies loaded by this Criteria. |
| public Criteria | Returns: this (for method chaining)The transformer to apply resultTransformer)Set a strategy for handling the query results. |
| public Criteria | Returns: this (for method chaining)The timeout value to apply. timeout)Set a timeout for the underlying JDBC query. |
| public Object | Returns: the single result or nullConvenience method to return a single instance that matches the query, or null if the query returns no results. |
| add | back to summary |
|---|---|
| public Criteria add(Criterion criterion) Add a | |
| addOrder | back to summary |
|---|---|
| public Criteria addOrder(Order order) Add an | |
| addQueryHint | back to summary |
|---|---|
| public Criteria addQueryHint(String hint) Add a DB query hint to the SQL. These differ from JPA's | |
| createAlias | back to summary |
|---|---|
| public Criteria createAlias(String associationPath, String alias) throws HibernateException Join an association, assigning an alias to the joined association.
Functionally equivalent to
| |
| createAlias | back to summary |
|---|---|
| public Criteria createAlias(String associationPath, String alias, JoinType joinType) throws HibernateException Join an association using the specified join-type, assigning an alias to the joined association.
The joinType is expected to be one of
| |
| createAlias | back to summary |
|---|---|
| public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException
Deprecated Join an association using the specified join-type, assigning an alias to the joined association.
The joinType is expected to be one of
| |
| createAlias | back to summary |
|---|---|
| public Criteria createAlias(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException Join an association using the specified join-type, assigning an alias to the joined association.
The joinType is expected to be one of
| |
| createAlias | back to summary |
|---|---|
| public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException
Deprecated Join an association using the specified join-type, assigning an alias to the joined association.
The joinType is expected to be one of
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath) throws HibernateException Create a new Criteria, "rooted" at the associated entity.
Functionally equivalent to
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath, JoinType joinType) throws HibernateException Create a new Criteria, "rooted" at the associated entity, using the specified join type.
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath, int joinType) throws HibernateException
Deprecated Create a new Criteria, "rooted" at the associated entity, using the specified join type.
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath, String alias) throws HibernateException Create a new Criteria, "rooted" at the associated entity, assigning the given alias.
Functionally equivalent to
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath, String alias, JoinType joinType) throws HibernateException Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type.
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException
Deprecated Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type.
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type.
| |
| createCriteria | back to summary |
|---|---|
| public Criteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException
Deprecated use Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type.
| |
| getAlias | back to summary |
|---|---|
| public String getAlias() Get the alias of the entity encapsulated by this criteria instance.
| |
| isReadOnly | back to summary |
|---|---|
| public boolean isReadOnly() Should entities and proxies loaded by this Criteria be put in read-only mode? If the read-only/modifiable setting was not initialized, then the default read-only/modifiable setting for the persistence context is returned instead.
| |
| isReadOnlyInitialized | back to summary |
|---|---|
| public boolean isReadOnlyInitialized() Was the read-only/modifiable mode explicitly initialized?
| |
| list | back to summary |
|---|---|
| public List Get the results.
| |
| scroll | back to summary |
|---|---|
| public ScrollableResults scroll() throws HibernateException Get the results as an instance of
| |
| scroll | back to summary |
|---|---|
| public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException Get the results as an instance of
| |
| setCacheable | back to summary |
|---|---|
| public Criteria setCacheable(boolean cacheable) Enable caching of this query result, provided query caching is enabled for the underlying session factory.
| |
| setCacheMode | back to summary |
|---|---|
| public Criteria setCacheMode(CacheMode cacheMode) Override the cache mode for this particular query. | |
| setCacheRegion | back to summary |
|---|---|
| public Criteria setCacheRegion(String cacheRegion) Set the name of the cache region to use for query result caching.
| |
| setComment | back to summary |
|---|---|
| public Criteria setComment(String comment) Add a comment to the generated SQL. | |
| setFetchMode | back to summary |
|---|---|
| public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException Specify an association fetching strategy for an association or a collection of values.
| |
| setFetchSize | back to summary |
|---|---|
| public Criteria setFetchSize(int fetchSize) Set a fetch size for the underlying JDBC query.
| |
| setFirstResult | back to summary |
|---|---|
| public Criteria setFirstResult(int firstResult) Set the first result to be retrieved.
| |
| setFlushMode | back to summary |
|---|---|
| public Criteria setFlushMode(FlushMode flushMode) Override the flush mode for this particular query. | |
| setLockMode | back to summary |
|---|---|
| public Criteria setLockMode(LockMode lockMode) Set the lock mode of the current entity. | |
| setLockMode | back to summary |
|---|---|
| public Criteria setLockMode(String alias, LockMode lockMode) Set the lock mode of the aliased entity. | |
| setMaxResults | back to summary |
|---|---|
| public Criteria setMaxResults(int maxResults) Set a limit upon the number of objects to be retrieved.
| |
| setProjection | back to summary |
|---|---|
| public Criteria setProjection(Projection projection) Used to specify that the query results will be a projection (scalar in
nature). Implicitly specifies the
The individual components contained within the given
| |
| setResultTransformer | back to summary |
|---|---|
| public Criteria setResultTransformer(ResultTransformer resultTransformer) Set a strategy for handling the query results. This determines the "shape" of the query result.
| |
| setTimeout | back to summary |
|---|---|
| public Criteria setTimeout(int timeout) Set a timeout for the underlying JDBC query.
| |
| uniqueResult | back to summary |
|---|---|
| public Object uniqueResult() throws HibernateException Convenience method to return a single instance that matches the query, or null if the query returns no results.
| |