Use of Detachedcriteria

Source: Internet
Author: User

The design can be flexibly based on the characteristics of the criteria to facilitate the assembly of query conditions.   Here's a summary of the usage of the criteria for Hibernate: Hibernate designed criteriaspecification as the parent interface for criteria, and the criteria and Detachedcriteria are provided below. The main difference between criteria and Detachedcriteria is that the form is different and the criteria is online, so it is created by the Hibernate Session, while the Detachedcriteria is offline and created without S Ession,detachedcriteria provides 2 static methods Forclass (Class) or Forentityname (Name) for Detachedcriteria instance creation.    The Spring Framework provides the gethibernatetemplate (). Findbycriteria (Detachedcriteria) method to easily return query results based on Detachedcriteria. Criteria and Detachedcriteria can be used to set query conditions using Criterion and Projection. You can set the Fetchmode (the mode of federated query fetching) and set the sorting method. For Criteria, you can also set Flushmodel (the way to flush sessions) and Lockmode (Database lock mode). 1:
Detachedcriteria Beautycriteria =detachedcriteria.forclass (beauty.class). Createcriteria ("Customers");
Beautycriteria.add (Restrictions.eq ("name", "Gates")):

2:
Detachedcriteria Beautycriteria =detachedcriteria.forclass (beauty.class). CreateAlias ("Customers", "C");
Beautycriteria.add (Restrictions.eq ("C.name", "Gates")):

Then there are new requirements, too old beauty do not, or to find a client gates, the conditions are as follows:
Detachedcriteria Beautycriteria =detachedcriteria.forclass (Beauty.class, "B").;
Detachedcriteria Customercriteria =beautycriteria.createalias ("Customers", C ");
Beautycriteria.add (Restrictions.le ("B.age", New Long (20)):
Customercriteria.add (Restrictions.eq ("C.name", "Gates")):


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use of Detachedcriteria

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.