0

如何将下面的 HQL 代码转换为 Hibernate Criteria 查询?

SELECT
    new com.project.to.PersonTO(
        person.firstName,
        person.lastName
    )
FROM
    Person person
4

1 回答 1

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));
于 2013-08-12T19:21:00.707 回答