Discriminator列映射为实体Hibernate

Discriminator列映射为实体Hibernate

本文介绍了Discriminator列映射为实体Hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在hibernate中,是否有可能将鉴别器作为一个实体?例如,如果我将Department作为基类,管理部门& ProcessingDepartment作为子类。 DepartmentType是鉴别器&是一个映射到DEPT_TYPE表的实体。

解决方案

是的,尽管这样的关系是只读的, ($)
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $部门{
...
@ManyToOne
@JoinColumn(name =DEPT_TYPE_ID,可插入= false,可更新= false)
私人部门类型deptType;
...
}


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.

解决方案

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;
    ...
}

这篇关于Discriminator列映射为实体Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:32