SQLQuery query = session.createSQLQuery("select * from user"); query.addEntity(User.class); List<User> list = query.list(); for(User user : list){ System.out.println(user.getId() + "--" + user.getUsername()); }
是通过hibernate.org.SQLQuery接口的实例对象来执行sql语句。