查询表里面的所有记录
1、通过Query对象查询
session = HibernateUtils.getSession();
ts = session.beginTransaction();
Query query = session.createQuery("from User");
List<User> list = query.list();
int i = 0;
for (User user : list) {
i ++;
System.out.println(i + user.toString());
}
2、通过criteria对象查询
3、通过SQLQuery对象实现
SQLQuery sq = session.createSQLQuery("select * from t_user");
sq.addEntity(User.class);
List<User> list = sq.list();
int i = 0;
for (User user : list) {
System.out.println(++i + user.toString());
}