【发布时间】:2012-07-23 14:45:37
【问题描述】:
用户实体
class User{
int id;
@OneToMany
Set<Role> roles;
}
:用户类还有很多我没有写的细节。
DTO
class DTO{
int id;
Set<Role> roles;
DTO(int id, Set<Role> roles){
this.id = id;
this.roles= roles;
}
}
查询
hibernateTemplate.find("select new DTO(u.id, r ) from "+User.class.getName()+ " u inner join u.roles as r");
问题:抛出未找到的有效构造函数。
通过以下构造函数修改,上述查询可以工作:
DTO(int id, Role role){
this.id = id;
}
问题:但现在它为同一用户提供了多个 DTO 记录,等于该用户拥有的角色数量。请帮忙。
【问题讨论】: