In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to realize Hibernate paging management". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to achieve Hibernate paging management"!
In Hibernate, through the design of unified interface for different databases, a transparent and universal paging mechanism is realized.
Set the paging range through Criteria.setFirstResult and Criteria.setFetchSize methods, such as:
Criteria criteria = session.createCriteria (TUser.class); criteria.add (Expression.eq ("age", "20")); / / 20 records criteria.setFirstResult (100) at the beginning of the 100th record from the search result; criteria.setFetchSize (20)
You can also set the paging range through the Query.setFirstResult and Query.setMaxResults methods, such as:
Query query = session.createQuery ("from TUser"); query.setFirstResult (100); query.setMaxResults (20); / / query.setFetchSize (20); List list = query.list ()
In Hibernate, the abstract class org.hibernate.dialect.Dialect specifies the external unified interface of all underlying databases. By providing corresponding Dialect implementation for different databases, the differences between databases can be eliminated, thus providing a transparent, database-independent storage layer foundation for the upper mechanism. For the paging mechanism, a method is defined in Dialect as follows:
/ * Add a LIMIT clause to the given SQL SELECT * * @ return the modified SQL * / public String getLimitString (String querySelect, boolean hasOffset) {throw new UnsupportedOperationException ("paged queries not supported");} public String getLimitString (String querySelect, int offset, int limit) {return getLimitString (querySelect, offset > 0);}
This method is used to construct the corresponding record return qualifying clause on the basis of the existing Select statements and according to the characteristics of each database. For example, the corresponding record qualification clause in MySQL is in Limit,Oracle and is implemented through the rownum clause. GetLimitString implementation in MySQLDialect:
Public String getLimitString (String sql, boolean hasOffset) {return new StringBuffer (sql.length () + 20) .append (sql) .append (hasOffset? "limit?,?": "limit?") .toString ();}
The implementation of the MySQLDialect.getLimitString method is actually implemented by appending limit, a proprietary SQL clause provided by MySQL, to a given Select statement.
GetLimitString implementation in Oracle9Dialect:
Public String getLimitString (String sql, boolean hasOffset) {sqlsql = sql.trim (); boolean isForUpdate = false; if (sql.toLowerCase (). EndsWith ("for update")) {sqlsql = sql.substring (0, sql.length ()-11); isForUpdate = true;} StringBuffer pagingSelect = new StringBuffer (sql.length () + 100); if (hasOffset) {pagingSelect.append ("select * from (select row_.*, rownum rownum_ from (")) } else {pagingSelect.append ("select * from (");} pagingSelect.append (sql); if (hasOffset) {pagingSelect.append (") row_ where rownum?");} else {pagingSelect.append (") where rownum
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.