0
我有3個表如下:Hibernate的許多一對一的關係刪除工作不正常
- 用戶具有用戶id
- UserProductEntitlement有帳戶及productId參數和一個布爾
- 產品先後的productId
這是我的課表示:
@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=?
我這裏有兩個問題:
- 爲什麼它被髮射更新,而不是刪除?
- 這是更大的問題 - where語句是用戶id =?而不是userId =?和productId =?
任何幫助/建議將不勝感激。
是的,我確實添加了它..Sorry,忘了將它添加在貼出的問題。這也沒有幫助。 – user483788 2010-10-24 22:32:51