QBC (Query By Criteria) QBE (Query By Example), qbcqbe
QBC reference: (QBC query of Hibernate)
// Is empty and is not empty @ Test public void testQBC () {Session session = sf. getCurrentSession (); session. beginTransaction (); // criterion standard/criterion/standard Criteria c = session. createCriteria (Topic. class) // from Topic. add (Restrictions. gt ("id", 2) // greater than = id> 2. add (Restrictions. lt ("id", 8) // less than = id <8. add (Restrictions. like ("title", "t _")). createCriteria ("category "). add (Restrictions. between ("id", 0, 5) // category. id> = 0 and category. id <= 5; // DetachedCriteria for (Object o: c. list () {Topic t = (Topic) o; System. out. println (t. getId () + "-" + t. getTitle ();} session. getTransaction (). commit ();}
QBE reference: (QBE and QBC of hibernate) and (Summary of Hibernate query methods (HQL, QBC, and QBE)
1 // is empty and is not empty 2 // QBC Query By Criteria 3 // QBE Query By Example 4 @ Test 5 public void testQBE () {6 Session session = sf. getCurrentSession (); 7 session. beginTransaction (); 8 9 Topic tExample = new Topic (); 10 tExample. setTitle ("T _"); 11 Example e = Example. create (tExample) 12. ignoreCase (). enableLike (); // construct example13 14 Criteria c = session. createCriteria (Topic. class) 15. add (Restrictions. gt ("id", 3) 16. add (Restrictions. lt ("id", 8) 17. add (e) 18; 19 20 for (Object o: c. list () {21 Topic t = (Topic) o; 22 System. out. println (t. getId () + "-" + t. getTitle (); 23} 24 session. getTransaction (). commit (); 25}
Jar package link: https://pan.baidu.com/s/1kVbVPmZ password: 384f
QBC link: https://pan.baidu.com/s/1dFEHIYt password: nfms
QBE link: https://pan.baidu.com/s/1i4JJa0d password: 2zby