我有2个班级,他们之间有多对多的关系。类是客户端和角色:
@Entity
@Table(name="iq_role")
public class Role extends IdEntity {
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "roles")
private Set<Client> clients = new LinkedHashSet<>();
}
和
@Entity
@Table(name="iq_client")
public class Client extends DeletableEntity {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "iq_client_roles", joinColumns = @JoinColumn(name="iq_client", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name="iq_role", referencedColumnName = "id"))
private Set<Role> roles = new HashSet<>();
}
当我选择一个特定的客户端并加入获取他的角色时,这就是SQL(由Hibernate生成):
select
client.id,
role.id
from
iq_client client
left outer join
iq_client_roles client_roles
on client.id = client_roles.iq_client
left outer join
iq_role role
on client_roles.iq_role = role.id
where
client.id=1
表iq_client
中的我在表iq_role
中有ID为3的记录我有ID 1和表iq_client_roles
的记录我有记录3,1。
当我复制这个生成的SQL并从控制台运行它时,我得到了正确的结果,但是hibernate显然无法将结果映射到对象中。
知道为什么吗?