开发者

Retrieving values of a specific field in Hibernate

Consider a class:

class Employee{
 Integer empId,
  //many other fields
}

I need a DAO method as shown below

 List<Integer> getAllEmployeeIds(){
 //??
 }
I dont want List<Employee> and  (NEW EDIT) Set<Intger>

How can i do that in hibernate?Am using hbm files fo开发者_如何转开发r mapping


Like this. Also, I recommend use querydsl to make it type-safe.

List<Integer> getAllEmployeeIds(){
    return (List<Integer>)createQuery("select e.empId from Employee e").list();
}


use an hql query and do something like

String hql = "select E.empId from Employee E";
Query query = session.createQuery(hql);
List<Integer> ids = query.list();

follow the documentation from here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜