package one; import java.util.Iterator; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class Demo { public static void main(String []args){ Configuration config=new Configuration().configure(); SessionFactory sf=config.buildSessionFactory(); Session session=sf.openSession(); Transaction trans=null; // trans.begin(); String sql="select max(age),count(*) from Employee"; Query query=session.createQuery(sql); // query.setString(0, "刘_"); List listEmployee=query.list(); // System.out.println(listEmployee.get(0)); Iterator iter=listEmployee.iterator(); while(iter.hasNext()){ // Employee empTemp=(Employee)iter.next(); // System.out.println(empTemp.getAddress()); Object []obj=(Object[])iter.next(); System.out.println(obj[0]); System.out.println(obj[1]); // System.out.println(iter.next()); } // Integer maxAge=(Integer)query.uniqueResult(); // System.out.println(maxAge); // System.out.println(((Employee)listEmployee.get(0)).getAddress()); // trans.commit(); // session.close(); } }