【发布时间】:2023-01-21 02:43:30
【问题描述】:
我在同一个表中有基本抽象类和 2 个实体,在休眠中使用描述符类型继承。
@MappedSuperclass()
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type", discriminatorType = DiscriminatorType.INTEGER)
public abstract class Relation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "bigint unsigned", name = "id")
public long id;
@Enumerated(EnumType.ORDINAL)
RelationType type;
}
@Table(name = "relation")
@Entity
@DiscriminatorValue("0")
public class Ban extends Relation {
// ...
public RelationType type = RelationType.BAN;
}
第二个实体相同,但使用@DiscriminatorValue("1")。
问题是:当通过单个存储库读取这些实体时,SQL 在“where”条件下不包含鉴别器值。
每个实体的单独存储库是必须的吗?
【问题讨论】: