Atitit. in Hibernate, Criteria uses summary and association query and queries o9o1 based on sub-objects. criteria, Criterion, 12. configure a repeat Association for the main object blackhead. criteria blackhead configuration association query... 24. atiMeata configuration Association @ CriteriaRelt25. Association createCriteria () 36.Cr
Atitit. in Hibernate, Criteria uses summary and association query and queries o9o by sub-object 1. criteria, Criterion, 1 2. the main object blackhead configuration repeat Association, 3 1 3. criteria blackhead configuration association query... 2 4. ati Meata configuration Association @ CriteriaRelt 2 5. associate createCriteria () 3 6. cr
In Atitit. Hibernate, Criteria uses summary and association query and queries o9o by sub-Object
1. Criteria, Criterion, 1
<2. Configure the Lei Association for the main object blackhead, 3: 1
3. Criteria blackhead configuration association query... 2
4. Ati Meata configuration Association @ CriteriaRelt 2
5. Associate createCriteria () 3
6. Use outline 4 for Criteria
7. Reference: 5
1. Criteria, Criterion ,,
Criteria is a more Object-Oriented Query Method than hql. Criteria can use Criterion and Projection to set query conditions. You can set the FetchMode (the mode of joint query capture) and the sorting mode. Criteria can also set FlushModel (the method of flushing sessions) and LockMode (the database lock mode ).
2. Configure Lei Association for the main object blackhead, and 3
Public class GvPlayRecord
Equipment eq;
/**
// Attilax old wow's paw 5_u_8 o9n
* @ Return the eq
*/
@ ManyToOne
@ NotFound (action = NotFoundAction. IGNORE)
@ JoinColumn (name = "equipment_id", insertable = false, updatable = false)
@ RemoteProperty
Public Equipment getEq (){
Return eq;
}
Criteria c = new BaseSvs (). getSession (). createCriteria (GvPlayRecord. class );
SimpleExpression se = Restrictions. eq ("eq. dpt. groupid", 114 );
// C. add (se );
List list = c. list ();
Iii. New eq. dpt. groupid attribute... it seems that the configuration of direct blackhead does not take effect ..
Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://blog.csdn.net/attilax
3. Criteria blacklist configuration association query...
Criteria c = new BaseSvs (). getSession (). createCriteria (GvPlayRecord. class );
Criteria eqCri = c. createCriteria ("eq ");
EqCri. add (Restrictions. eq ("departId", 117 ));
Middle Line lan...
4. Ati Meata configuration Association @ CriteriaRelt
@ CriteriaRelt (Signature = "departId ")
Equipment eq;
Framework processing code
// Yash condition process. def
SqlAti_Criteria SQL = new SqlAti_Criteria ();
SQL. reqMap = QueryPropertyssMap;
SQL. Criteria = c;
SQL. setCls (cls). addWhereExp (alias );
@ SuppressWarnings ("all") public SqlAti addWhereExp (Field alias ){
CriteriaRelt an = criteria. getAnnotation (CriteriaRelt. class );
If (! = Null)
{
Criteria crSub = this. Criteria. createCriteria (Criteria. getName ());
CrSub. add (Restrictions. eq (an. Equals (), this. reqMap. get (an. Equals ())));
}
Return this;
}
5. Associate createCriteria ()
4.
5.
You can use createCriteria () to easily establish constraints between correlated entities.
List cats = sess. createCriteria (Cat. class)
. Add (Restrictions. like ("name", "F % ")
. CreateCriteria ("kittens ")
. Add (Restrictions. like ("name", "F % ")
. List ();
Note that the second createCriteria () returns a new Criteria instance that references elements in the kittens set.
Next, the replacement form is also very useful in some cases.
List cats = sess. createCriteria (Cat. class)
. CreateAlias ("kittens", "kt ")
. CreateAlias ("mate", "mt ")
. Add (Restrictions. eqProperty ("kt. name", "mt. name "))
. List ();
(CreateAlias () does not create a new Criteria instance .)
The kittens set returned by the previous two queries saved by the Cat instance is not pre-filtered by the condition. If you want to only get
For eligible kittens, you must use returnMaps ().
List cats = sess. createCriteria (Cat. class)
. CreateCriteria ("kittens", "kt ")
. Add (Restrictions. eq ("name", "F % "))
. ReturnMaps ()
. List ();
Iterator iter = cats. iterator ();
While (iter. hasNext ()){
Map map = (Map) iter. next ();
Cat cat = (Cat) map. get (Criteria. ROOT_ALIAS );
Cat kitten = (Cat) map. get ("kt ");
}
6. Use outline for Criteria
5. Dynamic Association crawling
6. query example
The org. hibernate. criterion. Example class allows you to construct a conditional query using a given instance.
7. 7. Projections, aggregation, and grouping)
8. 8. Offline (detached) queries and subqueries
7. Reference ::
Full use of Criteria in Hibernate-LifeNote-BlogJava.htm