我在hibernate上定义了一个多对多的关系,如下所示:
用户
public class User{
private List<UserCustomer> userCustomerList;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "id.user", cascade=CascadeType.ALL)
public List<UserCustomer> getUserCustomerList() {
return userCustomerList;
}
}
用户客户
@Entity
@Table(name = "RTDB_USER_CUSTOMER")
@Component("userCustomerEntity")
@AssociationOverrides({
@AssociationOverride(name = "id.user",
joinColumns = @JoinColumn(name = "ID_USER")),
@AssociationOverride(name = "id.customer",
joinColumns = @JoinColumn(name = "ID_CUSTOMER")) })
public class UserCustomer {
@EmbeddedId
public UserCustomerId getId() {
return id;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumns({ @JoinColumn(name = "ID_ROLE_CUSTOMER", referencedColumnName = "ID") }) public RoleCustomer getRoleCustomer() {
return roleCustomer;
}
}
因此,用户有一个 UserCustomer 列表,代表用户对客户的角色。问题是,当我们将角色更改为 customer 并调用时update()
,我们不是更新了一行,而是使用相同的角色更新了所有行。当我们调用merge()
它时,它开始执行大量查询,然后给出stackoverflow
异常¿这可能是映射问题吗?