如何将下面的HQL代码转换为Hibernate Criteria查询?
SELECT
new com.project.to.PersonTO(
person.firstName,
person.lastName
)
FROM
Person person
答案 0 :(得分:1)
尝试下面的内容: -
Criteria criteria = session.createCriteria(Person.class);
criteria.setProjection(Projections.projectionList().add(Projections.property("firstName"), "firstName") .add(Projections.property("lastName"), "lastName"))
.setResultTransformer(new AliasToBeanResultTransformer(PersonTO.class));