1

I am using CascadeType.ALL but when I try to delete a record it just delete the record not its associated records.

@OneToMany(cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
public List<CartItem> getItems() {
    return items;
}

My tables are

cart
cartitem
cart_cartitem

When I use the following it just remove the record of cart_cartitem not the record of cartitem.

cart.getItems().remove(0);
session.update(cart);
J888
  • 1,944
  • 8
  • 42
  • 76

1 Answers1

1

Have you implemented equals and hashcode correctely? Also I believe that you are trying to remove orphans.

@OneToMany(mappedBy = "cart", 
   cascade={javax.persistence.CascadeType.ALL}, orphanRemoval = true)
private List<CartItem> getItems();
Community
  • 1
  • 1
Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118
  • can you please have a look at my other question as well thanks http://stackoverflow.com/questions/19148991/how-to-add-data-of-different-records-to-a-single-record – J888 Oct 20 '13 at 23:17