I have a simple eCommerce grails 5 application in which I define CartItem as:
class CartItem {
Customer customer
Product product
Integer quantity}
I have Product class:
class Product {
String name
Double price }
When a product is deleted, cartItem having this product(if any) must also be deleted. (The same also applies to Customer). Right now when I delete product, I get integrity violation exception if there is cartItem with this product.
I am using Hibernate with H2 in-memory database. Without using hibernate configuration (unless this is the only way) how can I achieve product delete cascade to automatic deletion of associate cartItem delete behaviour using grails GORM?
An instance of CartItem is created when a customer adds product to shopping cart.
When a cartItem is deleted (when a product is removed from the shopping cart) nothing happens to the related product or customer. But when a product is deleted its associated cartItem must also be deleted.