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