Hibernate Study Notes and hibernate Study Notes

Source: Internet
Author: User

Hibernate Study Notes and hibernate Study Notes
Hibernater HqlHibernater failed to query by page. The query result is all because:

Package com. tenni. test; import java. util. list; import org. hibernate. query; import org. hibernate. session; import org. hibernate. transaction; import org. junit. test; import com. tenni. entity. account; import com. tenni. entity. service; import com. tenni. util. hibernateUtil; public class testHql {private Session session = HibernateUtil. getSession (); private Transaction ts = session. getTransaction (); @ Test // public void testPaging () {int page = 1, pageSize = 3, totalRows, from; String hql = "select count (*) from Service "; Query qry = session. createQuery (hql); totalRows = Integer. valueOf (qry. uniqueResult (). toString (); System. err. println ("all count totalRows =" + totalRows); hql = "from Service order by id ";Qry=Session. createQuery (hql); // It must be before the start and capacity settingsFrom = (page-1) * pageSize;Qry. setFirstResult (from );// Set the start point and qry. setMaxResults (pageSize) from 0; // set the page sizeList <Service> list = qry. list (); for (Service a: list) {System. out. println (. getId () + "" +. getOsUserName () + "" +. getLoginPassword ());}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.