I have a many-to-many relationship defined on hibernate like this:
User
public class User{
private List<UserCustomer> userCustomerList;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "id.user", cascade=CascadeType.ALL)
public List<UserCustomer> getUserCustomerList() {
return userCustomerList;
}
}
UserCustomer
@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;
}
}
So a user has a list of UserCustomer, that represent roles of users over customers. The problem is, that when we change a role over a customer and call update()
, instead of one row updated we get all the rows updated with the same role. When we call merge()
it starts to perform a lots of queries and then gives stackoverflow
exception ¿Could this be a mapping problem?