I have read around that this is because I'm trying to persist an entity that has been otherwise removed, but I guess I'm not sure what constitutes "removed" or what makes an entity "removed". I'm trying to make the fairly basic OneToMany/ManyToOne with e.g. a shopping cart and items, items pointing back to parent cart. I want to be able to: -delete an item from the cart -delete the cart and all items
I have tried about 20 different examples, every time I google a new one I rush to try it. I am using annotations, something like:
Cart: @OneToMany(mappedBy="cart", cascade={CascadeType.ALL}) private Set<Item> items = new HashSet<>();
Item: @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "cart", insertable = false, updatable = false, nullable = false) private Cart cart;
I have tried @PreRemove on item to remove it from the cart's set, unlinking type methods on the entities to disconnect them before persisting etc. but it seems whatever I do I'm plagued by the "deleted entity passed to persist" error on committing the transaction. I have read so much my head is now spinning and feel far less confident about it than I did a few days ago - please could someone point me to a good example for this? Thanks, Phil
|