When i have only product class and two classes that extends product with inheritance strategy single table(product -> electronics , garden) it works properly.But if i try to create new single_table inheritance relationship (electronics -> smartphone,computer) i have a warn:
Discriminator column has to be defined in the root entity, it will be ignored in subclass: com.example.demo.entity.Electronics
Product class
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@DiscriminatorColumn(name = "type")
public abstract class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "info")
private String info;
@Column(name = "basic_characteristics")
private String basicCharacteristics;
@Column(name = "price")
private Integer price = 0;
}
Electronics Class:
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
@DiscriminatorValue("electronics")
@DiscriminatorColumn(name = "typeElectronics")
public class Electronics extends Product {
@Column(name = "electronics_data")
private String electronicsData;
}
Smartphone class:
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Data
@DiscriminatorValue("smartphone")
public class Smartphone extends Electronics{
@Column
private String smartphoneInfo;
}
I want to divide electronics class into two different entities with different fields.
https://docs.oracle.com/javaee/7/api/javax/persistence/DiscriminatorColumn.html
As per the documentation, I don't think
Electronicsclass in this example can have additional discriminator column for its child classes.