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