| Method |
Description |
| Restrictions. EQ |
= |
| Restrictions. alleq |
Use Map to impose multiple equal limits |
| Restrictions. gt |
> |
| Restrictions. Ge |
> = |
| Restrictions. lt |
< |
| Restrictions. Le |
<= |
| Restrictions. |
Between |
| Restrictions. Like |
Like |
| Restrictions. In |
In |
| Restrictions. And |
And |
| Restrictions. or |
Or |
| Restrictions. sqlrestriction |
Use SQL to limit queries |
Criteria query = hibernateutil. getsession (). createcriteria (entity. Class );
If (ID> 0)
{
Query. Add (restrictions. eq (ID,
Entity. GETID ()));
}
If (title! = NULL)
{
Query. Add (restrictions. Like (title,
Entity. gettitle (), matchmode. Anywhere ));
}
If (entity. getstatus ()>-1)
Query. Add (restrictions. In (status, arrayutils. toobject (New int [] {0, 1 })));
}
If (entity. getendtime ()> 0 &&
Entity. getstarttime ()> 0)
{
Query. Add (restrictions. Or (
Restrictions. Between (start_time,
Entity. getstarttime (),
Entity. getendtime ()),
Restrictions. Between (end_time,
Entity. getstarttime (),
Entity. getendtime ())));
// Query. Add (restrictions. Ge (start_time,
Entity. getstarttime ()));
// Query. Add (restrictions. Le (end_time,
Entity. getendtime ()));
}
Query. addorder (order. ASC (start_time ));
Query. Add (restrictions. sqlrestriction ("{alias}. ID in (select ID from user where manager_id =" + managerid + ")"));
Return query. List ();
Note:
Hibernate query, which learns to build a criteria query, In the criteria Query
Use the sqlrestriction () method to provide SQL syntax for restricted queries, such:
Criteria
Criteria = session. createcriteria (user. Class); criteria. Add (restrictions. sqlrestriction ("{alias}. Name
Like (?) "," Cater % ", hibernate. String); List users = criteria. List ();