|
|||||||||
| Home >> All >> org >> [ hibernate overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.hibernate
Interface Criteria

- All Superinterfaces:
- org.hibernate.criterion.CriteriaSpecification
- public interface Criteria
- extends org.hibernate.criterion.CriteriaSpecification
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();
| 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 |
| Method Summary | |
Criteria |
add(org.hibernate.criterion.Criterion criterion)
Add a restriction to constrain the results to be retrieved. |
Criteria |
addOrder(org.hibernate.criterion.Order order)
Add an ordering to the result set. |
Criteria |
createAlias(java.lang.String associationPath,
java.lang.String alias)
Join an association, assigning an alias to the joined association. |
Criteria |
createAlias(java.lang.String associationPath,
java.lang.String alias,
int joinType)
Join an association using the specified join-type, assigning an alias to the joined association. |
Criteria |
createCriteria(java.lang.String associationPath)
Create a new Criteria, "rooted" at the associated entity. |
Criteria |
createCriteria(java.lang.String associationPath,
int joinType)
Create a new Criteria, "rooted" at the associated entity, using the specified join type. |
Criteria |
createCriteria(java.lang.String associationPath,
java.lang.String alias)
Create a new Criteria, "rooted" at the associated entity, assigning the given alias. |
Criteria |
createCriteria(java.lang.String associationPath,
java.lang.String alias,
int joinType)
Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type. |
java.lang.String |
getAlias()
Get the alias of the entity encapsulated by this criteria instance. |
java.util.List |
list()
Get the results. |
ScrollableResults |
scroll()
Get the results as an instance of ScrollableResults |
ScrollableResults |
scroll(ScrollMode scrollMode)
Get the results as an instance of ScrollableResults based on the given scroll mode. |
Criteria |
setCacheable(boolean cacheable)
Enable caching of this query result, provided query caching is enabled for the underlying session factory. |
Criteria |
setCacheMode(CacheMode cacheMode)
Override the cache mode for this particular query. |
Criteria |
setCacheRegion(java.lang.String cacheRegion)
Set the name of the cache region to use for query result caching. |
Criteria |
setComment(java.lang.String comment)
Add a comment to the generated SQL. |
Criteria |
setFetchMode(java.lang.String associationPath,
FetchMode mode)
Specify an association fetching strategy for an association or a collection of values. |
Criteria |
setFetchSize(int fetchSize)
Set a fetch size for the underlying JDBC query. |
Criteria |
setFirstResult(int firstResult)
Set the first result to be retrieved. |
Criteria |
setFlushMode(FlushMode flushMode)
Override the flush mode for this particular query. |
Criteria |
setLockMode(LockMode lockMode)
Set the lock mode of the current entity |
Criteria |
setLockMode(java.lang.String alias,
LockMode lockMode)
Set the lock mode of the aliased entity |
Criteria |
setMaxResults(int maxResults)
Set a limit upon the number of objects to be retrieved. |
Criteria |
setProjection(org.hibernate.criterion.Projection projection)
Used to specify that the query results will be a projection (scalar in nature). |
Criteria |
setResultTransformer(org.hibernate.transform.ResultTransformer resultTransformer)
Set a strategy for handling the query results. |
Criteria |
setTimeout(int timeout)
Set a timeout for the underlying JDBC query. |
java.lang.Object |
uniqueResult()
Convenience method to return a single instance that matches the query, or null if the query returns no results. |
| Method Detail |
getAlias
public java.lang.String getAlias()
- Get the alias of the entity encapsulated by this criteria instance.
setProjection
public Criteria setProjection(org.hibernate.criterion.Projection projection)
- Used to specify that the query results will be a projection (scalar in
nature). Implicitly specifies the CriteriaSpecification.PROJECTION>
CriteriaSpecification.PROJECTION55 result transformer. The individual components contained within the given projection determines the overall "shape" of the query result.
add
public Criteria add(org.hibernate.criterion.Criterion criterion)
- Add a restriction to constrain the results to be
retrieved.
addOrder
public Criteria addOrder(org.hibernate.criterion.Order order)
- Add an ordering to the result set.
setFetchMode
public Criteria setFetchMode(java.lang.String associationPath, FetchMode mode) throws HibernateException
- Specify an association fetching strategy for an association or a
collection of values.
setLockMode
public Criteria setLockMode(LockMode lockMode)
- Set the lock mode of the current entity
setLockMode
public Criteria setLockMode(java.lang.String alias, LockMode lockMode)
- Set the lock mode of the aliased entity
createAlias
public Criteria createAlias(java.lang.String associationPath, java.lang.String alias) throws HibernateException
- Join an association, assigning an alias to the joined association.
Functionally equivalent to
createAlias(String, String, int)55 using CriteriaSpecification.INNER_JOIN>CriteriaSpecification.INNER_JOIN55 for the joinType.
createAlias
public Criteria createAlias(java.lang.String associationPath, java.lang.String alias, int 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 CriteriaSpecification.INNER_JOIN>
CriteriaSpecification.INNER_JOIN55 (the default), CriteriaSpecification.FULL_JOIN>CriteriaSpecification.FULL_JOIN55 , or CriteriaSpecification.LEFT_JOIN>CriteriaSpecification.LEFT_JOIN55 .
createCriteria
public Criteria createCriteria(java.lang.String associationPath) throws HibernateException
- Create a new Criteria, "rooted" at the associated entity.
Functionally equivalent to
createCriteria(String, int)55 using CriteriaSpecification.INNER_JOIN>CriteriaSpecification.INNER_JOIN55 for the joinType.
createCriteria
public Criteria createCriteria(java.lang.String associationPath, int joinType) throws HibernateException
- Create a new Criteria, "rooted" at the associated entity, using the
specified join type.
createCriteria
public Criteria createCriteria(java.lang.String associationPath, java.lang.String alias) throws HibernateException
- Create a new Criteria, "rooted" at the associated entity,
assigning the given alias.
Functionally equivalent to
createCriteria(String, String, int)55 using CriteriaSpecification.INNER_JOIN>CriteriaSpecification.INNER_JOIN55 for the joinType.
createCriteria
public Criteria createCriteria(java.lang.String associationPath, java.lang.String alias, int joinType) throws HibernateException
- Create a new Criteria, "rooted" at the associated entity,
assigning the given alias and using the specified join type.
setResultTransformer
public Criteria setResultTransformer(org.hibernate.transform.ResultTransformer resultTransformer)
- Set a strategy for handling the query results. This determines the
"shape" of the query result.
setMaxResults
public Criteria setMaxResults(int maxResults)
- Set a limit upon the number of objects to be retrieved.
setFirstResult
public Criteria setFirstResult(int firstResult)
- Set the first result to be retrieved.
setFetchSize
public Criteria setFetchSize(int fetchSize)
- Set a fetch size for the underlying JDBC query.
setTimeout
public Criteria setTimeout(int timeout)
- Set a timeout for the underlying JDBC query.
setCacheable
public Criteria setCacheable(boolean cacheable)
- Enable caching of this query result, provided query caching is enabled
for the underlying session factory.
setCacheRegion
public Criteria setCacheRegion(java.lang.String cacheRegion)
- Set the name of the cache region to use for query result caching.
setComment
public Criteria setComment(java.lang.String comment)
- Add a comment to the generated SQL.
setFlushMode
public Criteria setFlushMode(FlushMode flushMode)
- Override the flush mode for this particular query.
setCacheMode
public Criteria setCacheMode(CacheMode cacheMode)
- Override the cache mode for this particular query.
list
public java.util.List list() throws HibernateException
- Get the results.
scroll
public ScrollableResults scroll() throws HibernateException
- Get the results as an instance of ScrollableResults
scroll
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException
- Get the results as an instance of ScrollableResults based on the
given scroll mode.
uniqueResult
public java.lang.Object uniqueResult() throws HibernateException
- Convenience method to return a single instance that matches
the query, or null if the query returns no results.
|
|||||||||
| Home >> All >> org >> [ hibernate overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC