查詢表里面的所有記錄
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對象實現(xiàn)
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());
}