我需要进行一些选择并将其映射到自定义 DTO
public class SomeClass {
@PersistenceContext
private EntityManager em;
public void doSomething() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SomeClass2> criteria = builder.createQuery(SomeClass2.class);
Root<SomeClass2> root = criteria.from(SomeClass2.class);
Join<SomeClass3, SomeClass2> join = root.join("field");
... other joins and predicates ...
em.createQuery(criteria);
}
}
但
em.createQuery(criteria)
.unwrap(org.hibernate.query.Query.class)
.setResultTransformer(Transformers.aliasToBean(CustomDTO.class));
没有帮助。
我有一个例外
org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [net.package.api.SomeClass2].
Expected arguments are: java.lang.String, java.lang.String, Java.lang.String, long
这是否可以将 TypedQuery 映射到一些自定义 DTO?