Associated with ck1's answer, but with one table.
Using InheritanceType.JOINED requires a table for the base class and one table for each subclass. If you use InheritanceType.SINGLE_TABLE with DiscriminatorColumn , you can store all your objects in one table and still extract them from one collection. You can also combine DiscriminatorColumn with InheritanceType.JOINED if you want to find out what type of object is in the base class by storing separate subclass fields in separate tables.
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "DISC") public abstract class Bar { ... } @Entity @DiscriminatorValue("BAR1") public class Bar1 extends Bar { ... } @Entity @DiscriminatorValue("BAR2") public class Bar2 extends Bar { ... }
source share