In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to implement Hibernate Framework query". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement Hibernate Framework query.
1.Hibernate Query Language (HQL): it is the minimum OO Dialect of ANSI SQL, for example:
Session.createQuery ("from Category c where c.name like 'Laptop%'"); entityManager.createQuery ("select c from Category c where c.name like' Laptop%'")
2.Criteria query: it is an extension of HQL query and provides some advanced Hibernate Framework query functions, such as:
Session.createCriteria (Category.class) .add (Restrictions.like ("name", "Laptop%"); 3.Native SQL query: session.createSQLQuery ("select {c. *} from CATEGORY {c} where NAME like 'Laptop%'") .addEntity ("c", Category.class)
3.Native SQL query:
Session.createSQLQuery ("select {c. *} from CATEGORY {c} where NAME like 'Laptop%'") .addEntity ("c", Category.class)
Recently, I often encounter the task of querying Hibernate data in my project. I illustrate some of the more difficult topics I have encountered: "expressing SELECT".
Criteria crit = session.createCriteria (User.class) .setProjection (Projections.projectionList () .add (Projections.property ("lastname")) .add (Projections.property ("firstname")) .list ()
"express WHERE"
Criteria crit = session.createCriteria (User.class) .add (Restrictions.eq ("email", "foo@hibernate.org")) .uniqueResult ()
"express GROUP"
Criteria crit = session.createCriteria (User.class) .setProjection (Projections.projectionList () .add (Projections.groupProperty ("lastname")) .add (Projections.groupProperty ("firstname")) .list ()
"express ORDER"
Criteria crit = session.createCriteria (User.class) .addOrder (Order.asc ("lastname")) .addOrder (Order.asc ("firstname")) .list ()
"take TOP 5 results":
Criteria crit = session.createCriteria (Cat.class); .setMaxResults (5) .list ()
Paging:
Criteria crit = session.createCriteria (Cat.class) .setFirstResult (1) .setMaxResults (50) .list ()
"get query results": if you use select or group, you must use object [] to get the list value of the query result
If you are not using select or group, you must use java object [] to get the list value of the query result
Involves combining primary key properties:
Criteria crit = session.createCriteria (activitylog.class) .add (Restricts.eq ("comp_id.custId", customerid0)) .add (Restricts.ge ("createdTs", starttime)) .add (Restricts.le ("createdTs", endtime)) .list ()
Foreign Key federated query:
SQLQuery query = session.createSQLQuery ("select activitylog_seq.nextval as sessid from dual"); Query.addScalar ("sessid", Hibernate.LONG); Long long0 = query.uniqueResult (); now that you have a better understanding of "how to implement Hibernate Framework query", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.