Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Hibernate's Criteria Query?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report