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

How to use DetchedCriteria in Hibernate

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to use DetchedCriteria in Hibernate. It is very detailed and has a certain reference value. Friends who are interested must finish it!

Criteria is bound to Session, and its life cycle ends with the end of Session. When querying with Criteria, objects are dynamically created during execution each time, and various query conditions are added. As Session is recycled, Criteria is also recycled.

To be able to reuse Criteria objects, add org.hibernate.criterion.DetchedCriteria to Hibernate 3. You can first create a DetchedCriteria instance, add various query conditions, and then bind to Session when you need to query to get a Criteria object that binds Session, for example:

/ / first create DetchedCriteria object DetachedCriteria detchedCriteria = DetachedCriteria.forClass (User.class); / / add query condition detchedCriteria.add (Restrictions.ge ("age", new Integer (25)); Session session = sessionFactory.openSession (); / / bind Session and return a Criteria instance Criteria criteria = detchedCriteria.getExecutableCriteria (session); List users = criteria.list () The above is all the content of the article "how to use DetchedCriteria in Hibernate". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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