我需要进行一些选择并将其映射到自定义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?
答案 0 :(得分:0)
使用构造函数表达式和JPQL的DTO投影:
let data = [2, 4, 5, 8, 1, 9, 3];
let faulty = [2, 1, 5, 6];
let clean = data.filter(d => faulty.indexOf(d) < 0 );
console.log(clean);