文档介绍:hibernate hql语句使用(hibernate hql语句使用)
First, the use of aggregate functions in Hibernate
The Projections class of the Criteria interface is mainly used to help the Criteria interface plete the packet query and statistics function of the data:
List cats= ()
.setProjection ( ())
.add ( ())
.add ( ("weight"))
.add ( ("weight"))
.add ( ("weight"))
.add ( ("color"))
.addOrder ( ("color")).List ();
The example code is equivalent to:
Select color, count (*), AVG (weight), max (weight), min (weight), min (weight) from cat group by color ordy color asc;
Two, conditional query (Criteria Queries)
With an intuitive, extensible conditional query, API is the
feature of Hibernate.
1. create a Criteria instance
. interface represents a query for a particular persistent class. Session is a factory for Criteria instances.
Criteria crit = ();
(50);
List cats = ();
2. limit the content of the result set
A separate query condition is an instance of . interface. . class defines the factory method for obtaining some built-in Criterion types.
List cats = ()
.add ( ("name", "Fritz%"))
.add ( ("weight", minWeight, maxWeight)
.list ();
Constraints can be grouped logically.
List cats = ()
.add ( ("name", "Fritz%"))
.add ()
("age", new Integer (0)),
("age")
))
.list ();
List cats = ()
.add ( ("name", "new String[]", "Fritz", "Izi", "Pk"})
.add ( ())
.add ( ("age"))
.add ( ("age", new Integer (0))
.add (Restr