The following methods alters the behavior of the executed query, some can be a life saver, so check them all out.
cache(boolean cache=true, cacheRegion)
Tells Hibernate whether to cache the query or not (if the query cache is enabled), and optionally choose a cache region
Tells Hibernate the cache region to store the query under
Add a comment to the generated SQL.
Set's the fetch size of the underlying JDBC query
Specifies the offset for the results. A value of 0 will return all records up to the maximum specified.
Set a limit upon the number of objects to be retrieved.
Specifies both the sort property (the first argument, the sort order (either 'asc' or 'desc'), and if it should ignore cases or not
peek( target )
Peek into the criteria build process with your own closure that accepts the criteria itself.
Add a DB query hint to the SQL. These differ from JPA's QueryHint, which is specific to the JPA implementation and ignores DB vendor-specific hints. Instead, these are intended solely for the vendor-specific hints, such as Oracle's optimizers. Multiple query hints are supported; the Dialect will determine concatenation and placement.
Set the read-only/modifiable mode for entities and proxies loaded by this Criteria, defaults to readOnly=true
Set a timeout for the underlying JDBC query in milliseconds.
when( test, target )
A nice functional method to allow you to pass a boolean evaulation and if true, the target closure will be executed for you, which will pass in the criteria object to it.