|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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 Expression. eg.
List cats = session.createCriteria(Cat.class) .add( Expression.like("name", "Iz%") ) .add( Expression.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( Expression.like("name", "Iz%") ) .list();Hibernate's query language is much more general and should be used for non-simple cases.
Session.createCriteria(java.lang.Class)
,
Expression
,
Criterion
,
Order
Field Summary | |
static ResultTransformer |
ALIAS_TO_ENTITY_MAP
Each row of results is a Map from alias to entity instance |
static ResultTransformer |
DISTINCT_ROOT_ENTITY
Each row of results is a distinct instance of the root entity |
static String |
ROOT_ALIAS
The alias that refers to the "root" entity of the criteria query. |
static ResultTransformer |
ROOT_ENTITY
Each row of results is an instance of the root entity |
Method Summary | |
Criteria |
add(Criterion criterion)
Add a Criterion to constrain the results to be retrieved. |
Criteria |
addOrder(Order order)
Add an Order to the result set. |
Criteria |
createAlias(String associationPath,
String alias)
Join an association, assigning an alias to the joined entity |
Criteria |
createCriteria(String associationPath)
Create a new Criteria, "rooted" at the associated entity |
Criteria |
createCriteria(String associationPath,
String alias)
Create a new Criteria, "rooted" at the associated entity, assigning the given alias |
Class |
getCriteriaClass()
Get the persistent class that this Criteria applies to |
Class |
getCriteriaClass(String alias)
Get the persistent class that the alias refers to |
List |
list()
Get the results. |
Criteria |
returnMaps()
Deprecated. use setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP) |
Criteria |
returnRootEntities()
Deprecated. use setResultTransformer(Criteria.ROOT_ENTITY) |
Criteria |
setCacheable(boolean cacheable)
Enable caching of this query result set |
Criteria |
setCacheRegion(String cacheRegion)
Set the name of the cache region. |
Criteria |
setFetchMode(String associationPath,
FetchMode mode)
Specify an association fetching strategy for a one-to-many, many-to-one or one-to-one association, or for 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 |
setLockMode(LockMode lockMode)
Set the lock mode of the current entity |
Criteria |
setLockMode(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 |
setResultTransformer(ResultTransformer resultTransformer)
Set a strategy for handling the query results. |
Criteria |
setTimeout(int timeout)
Set a timeout for the underlying JDBC query. |
Object |
uniqueResult()
Convenience method to return a single instance that matches the query, or null if the query returns no results. |
Field Detail |
public static final ResultTransformer ALIAS_TO_ENTITY_MAP
public static final ResultTransformer ROOT_ENTITY
public static final ResultTransformer DISTINCT_ROOT_ENTITY
public static final String ROOT_ALIAS
Method Detail |
public Criteria setMaxResults(int maxResults)
maxResults
- the maximum number of results
public Criteria setFirstResult(int firstResult)
firstResult
- the first result, numbered from 0
public Criteria setFetchSize(int fetchSize)
fetchSize
- the fetch sizepublic Criteria setTimeout(int timeout)
timeout
-
public Criteria add(Criterion criterion)
criterion
-
public Criteria addOrder(Order order)
order
-
public List list() throws HibernateException
HibernateException
public Object uniqueResult() throws HibernateException
HibernateException
- if there is more than one matching resultpublic Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException
associationPath
- a dot seperated property pathmode
- the fetch mode
HibernateException
public Criteria createAlias(String associationPath, String alias) throws HibernateException
HibernateException
public Criteria createCriteria(String associationPath) throws HibernateException
HibernateException
public Criteria createCriteria(String associationPath, String alias) throws HibernateException
HibernateException
public Class getCriteriaClass()
public Class getCriteriaClass(String alias)
public Criteria returnMaps()
returnRootEntities()
public Criteria returnRootEntities()
returnMaps()
public Criteria setResultTransformer(ResultTransformer resultTransformer)
Criteria.ROOT_ENTITY
,
Criteria.DISTINCT_ROOT_ENTITY
,
Criteria.ALIAS_TO_ENTITY_MAP
public Criteria setLockMode(LockMode lockMode)
lockMode
- the lock modepublic Criteria setLockMode(String alias, LockMode lockMode)
alias
- an aliaslockMode
- the lock modepublic Criteria setCacheable(boolean cacheable)
public Criteria setCacheRegion(String cacheRegion)
cacheRegion
- the name of a query cache region, or null
for the default query cache
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |