Hi,
I don't really know if this is a bug or maybe model that I make is bad. I have a problem with with two different classes with OneToMany relation to one, shared class. For example (first class):
@Entity public static class Store { @OneToMany(targetEntity = Offer.class, mappedBy = "store") private List<Offer> offers; }
second class:
@Entity public static class Product { @OneToMany(targetEntity = Offer.class, mappedBy = "product", fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Set<Offer> offers; }
and a shared class Offer:
@Entity public static class Offer { @ManyToOne private Product product; @ManyToOne private Store store; }
Naming of this class is not perfect, but in my application Offer contains URL of product that I can parse for price. But this is not important here :) The main purpose of this, is to have all offers for products (one Product can have many Offers) and for a given store list of all Offers of all Products that belongs to this Store. This way I can easily iterate over all offers from all products for given store.
The problem is, that after removing product, all "connected" offers are also removed (cascade). After that, when I iterate over offers in store, there is null pointer about not finding offer (which is deleted together with product).
You can see this in attached example. The question is - is it a bug? Or I shouldn't use that kind of relations?