views:

25

answers:

1

Hi I have 3 tables as following 1) User has userId 2) UserProductEntitlement has userId and productId and a boolean 3) Product has productId

This is my class representation :

@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;

    }   

}

so initially when a user logs in all his entitlements are loaded. But when I try to remove a ProductEntitlement from viewableProduct set, hibernate is firing a update statement as update UserProductEntitlement set userId= null where userId=?

I have two issues here: 1) why it is firing update instead of delete? 2) This is the bigger problem -- where statement is userId=? instead of userId=? and productId=?

Any help/suggestion on this would be appreciated.

Thanks!

A: 

Looks like your forgot to add @Cascade annotation at viewableProduct.

See details here.

FoxyBOA
Yeah I did add it ..Sorry, forgot to add it in the posted question. That did not help either.