HQL Basic query results for output and iterator output

Source: Internet
Author: User

HQL First Class:

Hibernate query Language:hibernate querying language

  

Grammar:

Query

String hql= "from dept";

Query query=session.createquery (HQL);//Return list collection

Query is a list collection

HQL statement Next note detailed, this production simple operation!

    

1      Public StaticList<dept>getdept () {2List<dept> list=NewArraylist<dept>();3Configuration conf=NULL;4Sessionfactory factory=NULL;5Session session=NULL;6         7         Try {8             9conf=NewConfiguration (). Configure ();Ten             //Create Sessionfactory Onefactory=conf.buildsessionfactory (); A             //Open Session -session=factory.opensession (); -             //hql theString hql= "SELECT Dept from Dept as Dept where dept.deptname like '% hair% '"; -Query query=session.createquery (HQL); - //list=query.list (); - //For (Dept dep:list) { + //System.out.println (DEP); - //                 + //            } ASystem.out.println ("iterator"); atIterator<dept> ite=query.iterate (); -              while(Ite.hasnext ()) { - System.out.println (Ite.next ()); -                  -             } -              in              -}Catch(Exception e) { to e.printstacktrace (); +              -}finally{ the             if(session!=NULL){ * session.close (); $                 Panax Notoginseng             } -         } the          +          A          the         returnlist; +          -}

  

    

HQL Basic query results for output and iterator output

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.