问题
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.
回答1:
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;
...
}
来源:https://stackoverflow.com/questions/10273975/discriminator-column-mapped-as-entity-hibernate