开发者

Retrieving values of a specific field in Hibernate

开发者 https://www.devze.com 2023-03-22 12:37 出处:网络
Consider a class: class Employee{ Integer empId, //many other fields } I need a DAO method as shown below

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

精彩评论

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