At the moment I have the problem where I need an OneToMany ArrayList of different objects with the same interface.
For example:
@Entity
@Table(name = "store")
public class Store {
@OneToMany(mappedBy = "store")
private List<Product> allProducts;
}
public interface Product {
String getProductCode();
}
@Entity
@Table(name = "car")
public class Car implements Product{
int wheels;
}
@Entity
@Table(name = "computer")
public class Computer implements Product{
String cpu;
}
I just want it to be easy to add other products by just implementing the Product interface. But hibernate gives me this error: 'One To Many' attribute value type should not be 'Product'.
I found some posts about this issue but they are pretty old (5 years or older). They all ended up with that this wasn't possible back then.
Did hibernate add any functionality in the last 5 years to solve this problem or are there any other good ways of adding multiple objects in the same OneToMany relation? I don't want to update my Store class everytime I add a new product.