DAO Layer:
Offline query
Public list<emp> Findbydet (Detachedcriteria c) {
Return C.getexecutablecriteria (Hibernatesessionfactory.getsession ()). List ();
}
Biz Business Layer
Offline query
Public List Findbydet () {
Deptdao dao=new Deptdao ();
Detachedcriteria C=detachedcriteria.forclass (Emp.class, "C")
. Setprojection (
Projections.projectionlist ()
. Add (Projections.count ("Empno"))
. Add (Property.forname ("job"))
. Add (Projections.avg ("Sal"), "avg")
. Add (Projections.max ("Sal"))
. Add (Projections.min ("Sal"))
. Add (Projections.groupproperty ("Dept.deptno"))//dept will return the full Deptno
. Add (Property.forname ("Dept.deptno"). Group ())
)
Offline Query with Conditional
. Add (Restrictions.gt ("Dept.deptno", (byte) 10))
. AddOrder (ORDER.ASC ("avg"));
return Dao.findbydet (c);
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Detachedcriteria Offline Query Example