Skip to Content
Harnessing Hibernate
book

Harnessing Hibernate

by James Elliott, Timothy M. O'Brien, Ryan Fowler
April 2008
Intermediate to advanced content levelIntermediate to advanced
380 pages
11h 26m
English
O'Reilly Media, Inc.
Content preview from Harnessing Hibernate

Appendix B. The Criteria API

Criteria queries start by obtaining a Criteria object from the Session, using the createCriteria() method to identify the primary class (and thus table) on which the query is to be performed. Restrictions, projections, and orderings are then attached to the query using the factories described below, making it a very powerful and convenient interface.

The Criterion Factory

Hibernate provides the class org.hibernate.criterion.Restrictions as a factory for creating the Criterion instances you use to narrow down the objects (rows) you want from criteria queries. Restrictions defines a bunch of static methods you can invoke to conveniently create each of the standard Criterion implementations available in Hibernate, using parameters you supply. These criteria are used to determine which persistent objects from the database are included in the results of your query. The following table provides a summary of the available options.

MethodParametersPurpose
allEq Map propertiesA shortcut for requiring several properties to have particular values. The keys of the supplied map are the names of the properties you want to constrain, while the values in the map are the target values each property must equal if an entity is to be included in the query results. The returned Criterion ensures that each named property has the corresponding value.
and Criterion lhs, Criterion rhsBuilds a compound Criterion that requires both halves to be met in order for the whole to succeed. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Hibernate: For Hibernate 5

Beginning Hibernate: For Hibernate 5

Joseph B. Ottinger, Jeff Linwood, Dave Minter
Just Hibernate

Just Hibernate

Madhusudhan Konda
Beginning Hibernate, Third Edition

Beginning Hibernate, Third Edition

Joseph B. Ottinger, Dave Minter, Jeff Linwood

Publisher Resources

ISBN: 9780596517724Supplemental ContentErrata Page