HQL basic Query simple Query result for output and Iterator output, hqliterator

Source: Internet
Author: User

HQL basic Query simple Query result for output and Iterator output, hqliterator

The first HQL course:

Hibernate Query Language: hibernate Query Language

  

Syntax:

Query:

String hql = "from dept ";

Query query = session. createQuery (hql); // returns the list set.

Query is an object with many methods. The. list () method returns a set;

Detailed explanation of the next hql statement. This is a simple operation!

    

1 public static List <Dept> getDept () {2 List <Dept> list = new ArrayList <Dept> (); 3 Configuration conf = null; 4 SessionFactory factory = null; 5 Session session = null; 6 7 try {8 9 conf = new Configuration (). configure (); 10 // create sessionfactory11 factory = conf. buildSessionFactory (); 12 // open session 13 session = factory. openSession (); 14 // hql15 String hql = "select dept from Dept as dept where dept. deptname like '% sent %' "; 16 Query query = session. createQuery (hql); 17 // list = query. list (); 18 // for (Dept dep: list) {19 // System. out. println (dep); 20 // 21 //} 22 System. out. println ("Iterator"); 23 Iterator <Dept> ite = query. iterate (); 24 while (ite. hasNext () {25 System. out. println (ite. next (); 26 27} 28 29 30} catch (Exception e) {31 e. printStackTrace (); 32 33} finally {34 if (session! = Null) {35 session. close (); 36 37} 38} 39 40 41 42 return list; 43 44}

  

    

Related Article

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.