public static void main(String[] args) { String name = "德华"; List<User> list = criteriaQuery(name); for (Iterator<User> it = list.iterator(); it.hasNext(); ) { User user = it.next(); System.out.println(user.getId()); } }
/** * get load方式 * * @param id */ public static void getUser(int id) { Session session = null; User user = null; try { session = HibernateXmlCfgContext.getSession(); // user = (User) session.get(User.class, id); // 懒加载 user = (User) session.load(User.class, id); System.out.println(user.getClass()); Hibernate.initialize(user); } finally { if (session != null) session.close(); } }