import javax.persistence.PersistenceContext; import javax.persistence.Query; public class StudentServiceImpl { @PersistenceContext private EntityManager entityManager; public void getByHql() { String hql = "select * from Student"; Query query = entityManager.createQuery(hql); List<Student> list = query.getResultList(); } /** *查Map结果集 */ public void getMapByHql() { String hql = "select new Map(s.name as name, s.age as age) from Student s"; Query query = entityManager.createQuery(hql); List<Map<String, Object>> list = query.getResultList(); } }