我有3张表如下:
这是我的班级代表:
@Table(name="User")
class User
{
@OneToMany(fetch=FetchType.EAGER, targetEntity = ProductEntitlement.class, cascade=CascadeType.ALL)
@JoinColumn(name = "userId")
Set<ProductEntitlement> viewableProducts = new HashSet<ProductEntitlement>();
}
@Table(name = "UserProductEntitlement")
class ProductEntitlement
{
@EmbeddedId
private ProductEntitlementPk productPk;
@Column(name = "X_ENABLED")
@Type(type = "yes_no")
private Boolean xEnabled;
@Embeddable
private static class ProductEntitlementPk implements Serializable {
ProductEntitlementPk() {
}
ProductEntitlementPk(User user, Product baseProduct) {
this.role = role;
this.baseProduct = baseProduct;
}
@ManyToOne( optional = false, targetEntity = User.class)
@ForeignKey(name = "FK_USER")
@JoinColumn(name = "userId", nullable = false)
private User user;
@OneToOne(optional = false, targetEntity = BaseProduct.class)
@ForeignKey(name = "FK_Product")
@JoinColumn(name = "productId", nullable = false)
private Product baseProduct;
}
}
因此,最初当用户登录时,他的所有权利都会被加载。但是当我尝试从viewableProduct集中删除ProductEntitlement时,hibernate正在触发更新语句:
update UserProductEntitlement set userId= null where userId=?
我有两个问题:
对此有任何帮助/建议将不胜感激。