I would like to share the parent ID with the child entities.
So I would like to achieve something like this:
parent table
id | childName | ...
1 | childA | ...
2 | childB | ...
childA table
id | childASpecific | ...
1 | ASpecificValue | ...
childB table
id | childBSpecific | ...
2 | BSpecificValue | ...
Is there a way to do this in hibernate?
CodePudding user response:
In the meantime, I found the solution:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Parent {
@Id
private Long id;
private String childName;
// constructor, getters, setters
}
@Entity
public class ChildA extends Parent {
private String childASpecific;
// constructor, getters, setters
}
@Entity
public class ChildB extends Parent {
private String childBSpecific;
// constructor, getters, setters
}