Hibernate query for selecting multiple values

前端 未结 6 1777
鱼传尺愫
鱼传尺愫 2020-12-13 19:32

In hibernate I can do following

Query q = session.createQuery(\"from Employee as e);
List emps = q.list();

Now if I want to

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 20:38

    You will get a list of arrays of Objects (each one with two elements)

    List< Object[] > employees = q.list();
    
    for ( Object[] employee : employees ) {
        // employee[0] will contain the first name
        // employee[1] will contail the ID
    }
    

提交回复
热议问题