在Servlet中查询集合对象
关键代码如下
PrintWriter out = response.getWriter();
Configuration configuration = new Configuration().configure("./hibernate.cfg.xml");
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Query query = session.createQuery("from UserEntity");
List<UserEntity> list = query.list();
需要注意的是hibernate.cfg.xml
输出结果: