如何将休眠条件结果集映射到 java class?

how can map the hibernate criteria resultset to the java class?

我有一个有很多字段的实体,我需要通过查询获取其中的一些字段并保存在 java class 中? 我知道如何设置投影并获取指定字段,但我不知道如何将结果集映射到 java class.

this is my query:

    Criteria criteria=session.createCriteria(EmployeeInfo.class);
    Criterion condition1= Restrictions.eq("employeeTO.id",id);  
    criteria.add(condition1);
    criteria.setProjection(Projections.projectionList()
            .add(Projections.property("name"))
            .add(Projections.property("birthDay")));

i need to save result to list of below class

public class SubEmployeeInfo{
    String name;
    int brithDay;
}

如何将 critria.list() 保存到 List<SubEmployeeInfo> 中?

i have used below code but all field of returned SubEmployeeInfo object is null

criteria.setResultTransformer(Transformers.aliasToBean(HokmKargoziniDTO.class));
SubEmployeeInfoList = (List<SubEmployeeInfo>) criteria.list();

您可以使用 setResultTransformer 方法,同时构建 criteria. ResultTransformer 对象可以创建您将结果编组为任何所需格式。

示例:

criteria.setResultTransformer(Transformers.aliasToBean(SubEmployeeInfo.class));