HQL查询
HQL的简单查询
public static void demo() {
Session session = HibernateUtils.getCurrentSession();
Transaction trans = session.beginTransaction();
//简单查询
// sql中支持 * 的写法:select * from cst_customer; 但是在HQL中不支持* 的写法。
/*
Query query = session.craeteQuery("select * from Custome");
报错 List<Customer> list = query.list();
*/
String sql = "from Customer";
Query query = session.createQuery(sql);
List<Customer> list =query.list();
for (Customer customer : list) {
System.out.println(customer);
}
trans.commit();
}