Get the App
SLTechnology News&Howtos  ›  Development  › 

What is Hibernate's Criteria Query?

Shulou Source: shulou.com Published: 2022-06-02 08:00:10 10月03日 Update

This article mainly explains "what is the Criteria Query of Hibernate". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the Criteria Query of Hibernate"?

Criteria Query encapsulates the data query condition into an object through object-oriented design. To put it simply, Criteria Query can be seen as an object representation of traditional SQL, such as:

Criteria criteria=session.createCriteria (TUser.class); criteria.add (Expression.eq ("name", "Erica")); criteria.add (Expression.eq ("sex", new Integer (1))

The criteria instance here is essentially an encapsulation of SQL "select * from t_user where name='Erica' and sex=1". At run time, Hibernate generates the corresponding SQL statement based on the query criteria specified in Criteria.

Criteria query expression: Criteria itself is just a container, and the specific query conditions are added to the Criteria instance through the Criteria.add method.

Method description: Expression.eq corresponds to SQL "field=value" expression

For example, Expression.eq ("name", "Erica")

The Expression.allEq parameter is a Map object that contains multiple attribute-value relationships. Superimposed Expression.gt corresponding to multiple Expression.eq relationships corresponds to SQL "field > value" expression Expression.ge corresponds to SQL "field > = value" expression Expression.lt corresponds to SQL "fieldfield" Expression.gtProperty is used to compare values between two attributes, corresponding SQL "field > = field" Expression.ltProperty is used to compare values between two attributes, and corresponds to SQL "field"

Tags: Queries expressions instances objects properties conditions methods grouping statements statistics two between code can pass period line period encapsulation generation combination content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno Shulou Technology macOS Shulou Information