#Spring Boot Single Table Inheritance

3 messages · Page 1 of 1 (latest)

cinder sierra
#

Hey! I am building a project, and I decided to use single table strategy as my entity inheritance, but this is the first time I had to use it. So my question is that how should I build a service for this starategy?
For simplicity, and because the content of the classes doesnt really matter, I will provide schematic example
(lombok annotations are excluded for the sake of space):

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "discriminator")
@DiscriminatorValue("Common")
public class A{}

@Entity
@DiscriminatorValue("disc1")
public class B extends A{}

@Entity
@DiscriminatorValue("disc2")
public class C extends A{}

Now I have a repository or all 3 classes separately, but I planned to create 1 service class for the entire inheritance tree. I can understand why it would make more sense to make 1 for each of them, but I am curious if I can make only a single one. Also there are scenarios when I want to query all subtypes of A including A, so then it would make sense to have everything in 1 place. At least for me.
All help is appreciated!

supple widgetBOT
#

This post has been reserved for your question.

Hey @cinder sierra! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.