This might sound simple, but it is not working as it was supposed to be... I think I might be missing something...
I have the following code with ManyToMany but when I insert a Product in the Basket's product list it does not persist and does not update the list from the Product.
Code:
@Entity
@Table(name = "PRODUCT")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Product implements java.io.Serializable
{
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(name="BASKET_PRODUCT",
joinColumns={@JoinColumn(name="PRODUCT_ID", nullable=false)},
inverseJoinColumns={@JoinColumn(name="BASKET_ID", nullable=false)})
List<Basket> baskets;
}
Code:
@Entity
@Table(name = "BASKET")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Basket implements java.io.Serializable
{
@ManyToMany(mappedBy="baskets", cascade=CascadeType.ALL)
List<Product> products;
public void addProduct(Product product)
{
this.products.add(product);
}
}