日期:2014-05-20 浏览次数:20722 次
package cho3.hibernate; 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 TestHQL { public static void main(String[] args) { SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); // Transaction tx = session.beginTransaction(); String HQL1="select user.name from User user"; Query query1=session.createQuery(HQL1); List list1=query1.list(); Iterator it=list1.iterator(); System.out.print(it.next()); while(it.hasNext()) { System.out.print(it.next()); } // tx.commit(); session.close(); sessionFactory.close(); } }