如何检索列表,并使用new-operator在JPA查询中设置(一对多)。
例如,我有下一个课程:
@Entity
JobDetails {
private String name;
@OneToMany
private Set<Items> items;
private Customer c;
}
@Entity
Customer {
private int merchantId;
}
UserAndCustomerDto{
private int merchantId;
private String name;
private Set<Items> items;
public UserAndCustomerDto(int merchantId, String name, Set<Items> items) {
...
}
}
这是带有选择查询的存储库:
@Query("
select new UserAndCustomerDto(
c.merchantId,
j.name,
items
) from Job j
left join j.c as c
left join j.items as items
")
UserAndCustomerDto findDto()
并且异常是关于无效的构造函数的,所以 而不是使用
构建DTOnew DTO (String, int, Set < Item > )
它试图构建它:
new DTO (String, int, Item)
根据doc-n,它应该可以工作:HQL Doc
如何解决此问题,或者有可能使用Hibernate Criteria建立此查询吗?