如何将下面的 HQL 代码转换为 Hibernate Criteria 查询?
SELECT
new com.project.to.PersonTO(
person.firstName,
person.lastName
)
FROM
Person person
试试下面: -
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));