Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discriminator column mapped as entity Hibernate

In hibernate, is it possible to have discriminator as an entity? For example, if I have Department as the base class & AdminDepartment & ProcessingDepartment as subclasses. DepartmentType is the discriminator & is an entity mapped to DEPT_TYPE table.

like image 271
Rakesh Avatar asked Nov 29 '25 16:11

Rakesh


1 Answers

Yes, it's possible, though such a relationship will be read-only:

@Entity @Inheritence(...)
@DiscriminatorColumn(name = "DEPT_TYPE_ID")
public class Department {
    ...
    @ManyToOne
    @JoinColumn(name = "DEPT_TYPE_ID", insertable = false, updatable = false)
    private DepartmentType deptType;
    ...
}
like image 165
axtavt Avatar answered Dec 02 '25 07:12

axtavt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!