I'm using spring boot and Hibernate. What I'm trying is to have a single table for Materials and one for Costs.
What I want to know is if there's a way to specify in a subclass of Cost
the specific type of material (Subclass of Material
) it should handle. In the end, what I will like is that in order to create a SpecificCost
, a SpecificMaterial
should be provided not just a general Material
.
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Material {}
@Entity
public class SpecificMaterial extends Material {}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Cost {
@ManyToOne
private Material material;
}
@Entity
public class SpecificCost extends Cost{
/*
* I want to be able to specify that the field "material"
* that comes from the parent class
* should be of type SpecificMaterial a subclass of Material
*/
}
I tried to solve this with generics but it's not possible to use genetics in mapped columns. I have also tried with every one of the inheritance schemes but I haven't been able to. Does anyone know if there's a way to accomplished what I'm trying here?