Querying with criteria and example We first look (Web server info)
Querying with criteria and example We first look at regular joins and how you can express restrictions that involve associated classes. Joining associations for restriction There are two ways to express a join in the Criteria API; hence there are two ways in which you can use aliases for restriction. The first is the createCriteria() method of the Criteria interface. This basically means you can nest calls to createCriteria(): Criteria itemCriteria = session.createCriteria(Item.class); itemCriteria.add( Restrictions.like(”description”, “Foo”, MatchMode.ANYWHERE) ); Criteria bidCriteria = itemCriteria.createCriteria(”bids”); bidCriteria.add( Restrictions.gt( “amount”, new BigDecimal(99) ) ); List result = itemCriteria.list(); You usually write the query as follows (method chaining): List result = session.createCriteria(Item.class) .add( Restrictions.like(”description”, “Foo”, MatchMode.ANYWHERE) ) .createCriteria(”bids”) .add( Restrictions.gt(”amount”, new BigDecimal(99) ) ) .list(); The creation of a Criteria for the bids of the Item results in an inner join between the tables of the two classes. Note that you may call list() on either Criteria instance without changing the query result. Nesting criteria works not only for collections (such as bids), but also for single-valued associations (such as seller): List result = session.createCriteria(Item.class) .createCriteria(”seller”) .add( Restrictions.like(”email”, “%@hibernate.org”) ) .list(); This query returns all items that are sold by users with a particular email address pattern.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.