4

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?

4

1 に答える 1

1

表と更新コードを投稿できますか?

すべてのロールを更新する必要があるロールを直接更新していると思います。UserCustomer私の理解では、更新したくないUserCustomerだけRoleCustomerです。ではなく、フェッチRoleCustomerして更新してみてくださいUserCustomer

于 2012-12-05T12:24:16.307 に答える