org.hibernate.Criteria |
Known Indirect Subclasses |
Criteria is a simplified API for retrieving entities
by composing Criterion objects. This is a very
convenient approach for functionality like "search" screens
where there is a variable number of conditions to be placed
upon the result set.
The Session is a factory for Criteria.
Criterion instances are usually obtained via
the factory methods on Restrictions. eg.
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();
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.hibernate.criterion.CriteriaSpecification
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.hibernate.criterion.CriteriaSpecification
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add a
restriction to constrain the results to be
retrieved. | |||||||||||
Add an
ordering to the result set. | |||||||||||
Join an association using the specified join-type, assigning an alias
to the joined association.
| |||||||||||
Join an association, assigning an alias to the joined association.
| |||||||||||
Join an association using the specified join-type, assigning an alias
to the joined association.
| |||||||||||
Create a new Criteria, "rooted" at the associated entity.
| |||||||||||
Create a new Criteria, "rooted" at the associated entity, using the
specified join type.
| |||||||||||
Create a new Criteria, "rooted" at the associated entity,
assigning the given alias.
| |||||||||||
Create a new Criteria, "rooted" at the associated entity,
assigning the given alias and using the specified join type.
| |||||||||||
Create a new Criteria, "rooted" at the associated entity,
assigning the given alias and using the specified join type.
| |||||||||||
Get the alias of the entity encapsulated by this criteria instance.
| |||||||||||
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.
| |||||||||||
Was the read-only/modifiable mode explicitly initialized?
| |||||||||||
Get the results.
| |||||||||||
Get the results as an instance of
ScrollableResults based on the
given scroll mode. | |||||||||||
Get the results as an instance of
ScrollableResults | |||||||||||
Override the cache mode for this particular query.
| |||||||||||
Set the name of the cache region to use for query result caching.
| |||||||||||
Enable caching of this query result, provided query caching is enabled
for the underlying session factory.
| |||||||||||
Add a comment to the generated SQL.
| |||||||||||
Specify an association fetching strategy for an association or a
collection of values.
| |||||||||||
Set a fetch size for the underlying JDBC query.
| |||||||||||
Set the first result to be retrieved.
| |||||||||||
Override the flush mode for this particular query.
| |||||||||||
Set the lock mode of the aliased entity
| |||||||||||
Set the lock mode of the current entity
| |||||||||||
Set a limit upon the number of objects to be retrieved.
| |||||||||||
Used to specify that the query results will be a projection (scalar in
nature).
| |||||||||||
Set the read-only/modifiable mode for entities and proxies
loaded by this Criteria.
| |||||||||||
Set a strategy for handling the query results.
| |||||||||||
Set a timeout for the underlying JDBC query.
| |||||||||||
Convenience method to return a single instance that matches
the query, or null if the query returns no results.
|
Add a restriction
to constrain the results to be
retrieved.
criterion | The criterion object representing the
restriction to be applied. |
---|
Join an association using the specified join-type, assigning an alias to the joined association.
The joinType is expected to be one ofINNER_JOIN
(the default),
FULL_JOIN
, or LEFT_JOIN
.associationPath | A dot-seperated property path |
---|---|
alias | The alias to assign to the joined association (for later reference). |
joinType | The type of join to use. |
HibernateException | Indicates a problem creating the sub criteria |
---|
Join an association, assigning an alias to the joined association.
Functionally equivalent tocreateAlias(String, String, int)
using
INNER_JOIN
for the joinType.associationPath | A dot-seperated property path |
---|---|
alias | The alias to assign to the joined association (for later reference). |
HibernateException | Indicates a problem creating the sub criteria |
---|
Join an association using the specified join-type, assigning an alias to the joined association.
The joinType is expected to be one ofINNER_JOIN
(the default),
FULL_JOIN
, or LEFT_JOIN
.associationPath | A dot-seperated property path |
---|---|
alias | The alias to assign to the joined association (for later reference). |
joinType | The type of join to use. |
withClause | The criteria to be added to the join condition (ON clause) |
HibernateException | Indicates a problem creating the sub criteria |
---|
Create a new Criteria, "rooted" at the associated entity.
Functionally equivalent tocreateCriteria(String, int)
using
INNER_JOIN
for the joinType.associationPath | A dot-seperated property path |
---|
HibernateException | Indicates a problem creating the sub criteria |
---|
Create a new Criteria, "rooted" at the associated entity, using the specified join type.
associationPath | A dot-seperated property path |
---|---|
joinType | The type of join to use. |
HibernateException | Indicates a problem creating the sub criteria |
---|
Create a new Criteria, "rooted" at the associated entity, assigning the given alias.
Functionally equivalent tocreateCriteria(String, String, int)
using
INNER_JOIN
for the joinType.associationPath | A dot-seperated property path |
---|---|
alias | The alias to assign to the joined association (for later reference). |
HibernateException | Indicates a problem creating the sub criteria |
---|
Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type.
associationPath | A dot-seperated property path |
---|---|
alias | The alias to assign to the joined association (for later reference). |
joinType | The type of join to use. |
HibernateException | Indicates a problem creating the sub criteria |
---|
Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type.
associationPath | A dot-seperated property path |
---|---|
alias | The alias to assign to the joined association (for later reference). |
joinType | The type of join to use. |
withClause | The criteria to be added to the join condition (ON clause) |
HibernateException | Indicates a problem creating the sub criteria |
---|
Get the alias of the entity encapsulated by this criteria instance.
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.
IllegalStateException | if isReadOnlyInitialized() returns false
and this Criteria is not associated with a session. |
---|
Was the read-only/modifiable mode explicitly initialized?
Get the results.
HibernateException | Indicates a problem either translating the criteria to SQL, exeucting the SQL or processing the SQL results. |
---|
Get the results as an instance of ScrollableResults
based on the
given scroll mode.
scrollMode | Indicates the type of underlying database cursor to request. |
---|
ScrollableResults
representing the matched
query results.HibernateException | Indicates a problem either translating the criteria to SQL, exeucting the SQL or processing the SQL results. |
---|
Get the results as an instance of ScrollableResults
ScrollableResults
representing the matched
query results.HibernateException | Indicates a problem either translating the criteria to SQL, exeucting the SQL or processing the SQL results. |
---|
Override the cache mode for this particular query.
cacheMode | The cache mode to use. |
---|
Set the name of the cache region to use for query result caching.
cacheRegion | the name of a query cache region, or null for the default query cache |
---|
Enable caching of this query result, provided query caching is enabled for the underlying session factory.
cacheable | Should the result be considered cacheable; default is to not cache (false). |
---|
Add a comment to the generated SQL.
comment | a human-readable string |
---|
Specify an association fetching strategy for an association or a collection of values.
associationPath | a dot seperated property path |
---|---|
mode | The fetch mode for the referenced association |
HibernateException | Indicates a problem applying the given fetch mode |
---|
Set a fetch size for the underlying JDBC query.
fetchSize | the fetch size |
---|
Set the first result to be retrieved.
firstResult | the first result to retrieve, numbered from 0 |
---|
Override the flush mode for this particular query.
flushMode | The flush mode to use. |
---|
Set the lock mode of the aliased entity
alias | The previously assigned alias representing the entity to which the given lock mode should apply. |
---|---|
lockMode | The lock mode to be applied |
Set the lock mode of the current entity
lockMode | The lock mode to be applied |
---|
Set a limit upon the number of objects to be retrieved.
maxResults | the maximum number of results |
---|
Used to specify that the query results will be a projection (scalar in
nature). Implicitly specifies the PROJECTION
result transformer.
projection
determines the overall "shape" of the
query result.projection | The projection representing the overall "shape" of the query results. |
---|
Set the read-only/modifiable mode for entities and proxies loaded by this Criteria. This setting overrides the default setting for the persistence context.
readOnly | 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 mode |
---|
To set the default read-only/modifiable setting used for
entities and proxies that are loaded into the session:
setDefaultReadOnly(boolean)
Read-only entities are not dirty-checked and snapshots of persistent
state are not maintained. Read-only entities can be modified, but
changes are not persisted.
When a proxy is initialized, the loaded entity will have the same
read-only/modifiable setting as the uninitialized
proxy has, regardless of the session's current setting.
The read-only/modifiable setting has no impact on entities/proxies
returned by the criteria that existed in the session before the criteria was executed.
Set a strategy for handling the query results. This determines the "shape" of the query result.
resultTransformer | The transformer to apply |
---|
Set a timeout for the underlying JDBC query.
timeout | The timeout value to apply. |
---|
Convenience method to return a single instance that matches the query, or null if the query returns no results.
HibernateException | if there is more than one matching result |
---|