I want to achieve something like this:
@Entity
@Table(name = "beer")
public class Beer {
@Id Long id;
String brand;
String name;
}
@Entity
public class BeerWithIngredients extends Beer {
@OneToMany(mappedBy="beer")
List<BeerIngredient> ingredients;
}
@Entity
public class BeerIngredient {
@Id Long id;
// .. whatever fields
@ManyToOne
@JoinColumn(name = "beer_id")
BeerWithIngredient beer;
}
Physically, all beer data is in one table, but I want to split it into more entities.
Please note that:
- I would not like to use discriminator column in the database
- There isn't a column that I could use for
@DiscriminatorFormula
- I do not want to embed
Beer
insideBeerWithIngredients
, because it essentially is not a composition, but proper inheritance
Is there a way of achieving this with JPA (Hibernate)? Right now it complains about missing discriminator column, that I don't plan to provide.