在hibernate状态下,我可以执行以下操作
Query q = session.createQuery("from Employee as e); List<Employee> emps = q.list();
现在,如果我想获取int和String怎么办?
Query q = session.createQuery(""SELECT E.firstName,E.ID FROM Employee E"; List ans = q.list();
现在列表的结构是什么?
这可以。您唯一需要了解的是它将返回Object []如下列表:
Object []
Query q = session.createQuery("select e.id, e.firstName from Employee e"); List<Object[]> employees= (List<Object[]>)q.list(); for(Object[] employee: employees){ Integer id = (Integer)employee[0]; String firstName = (String)employee[1]; ..... }