gpt4 book ai didi

java - Eclipse 链接/JPA : Multiple @DiscriminatorColumn annotations for Entity

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:40:04 24 4
gpt4 key购买 nike

我正在 EclipseLink 中寻找一种在同一实体上有两个 @DiscriminatorColumns 的方法

我的 PostreSQL 数据库表是:

Dictionary
{
id,
object_type,
attribute_type,
translation
}

类是:

@Entity
@Table(name = "dictionary")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="object_type",
discriminatorType=DiscriminatorType.INTEGER)
public class DictionaryRow implements Serializable;

@Entity
@DiscriminatorValue("0")
@DiscriminatorColumn(name="info_type",
discriminatorType=DiscriminatorType.INTEGER)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class DictionaryAttribute extends DictionaryRow;

@Entity
@DiscriminatorValue("1")
public class DictionaryAttributeName extends DictionaryAttribute;

我想要实现的是,当我调用 DictionaryAttributeName 时,它​​将被解析为 SQL,如下所示:

select * from DICTIONARY where info_type = 1 and object_type = 0

但实际上,它从 DictionaryRow 类中获取 DiscriminatorColumn,从 DictionaryAttributeName 中获取 DiscriminatorValue,导致完全错误的 SQL:

select * from DICTIONARY where object_type = 1

这个问题有解决方案吗?

谢谢

最佳答案

根据 JPA 2.0 规范,这是不可能的:

11.1.10 DiscriminatorColumn Annotation

For the SINGLE_TABLE mapping strategy, and typically also for the JOINED strategy, the persistence provider will use a type discriminator column. The DiscriminatorColumn annotation is used to define the discriminator column for the SINGLE_TABLE and JOINED inheritance mapping strategies.

The strategy and the discriminator column are only specified in the root of an entity class hierarchy or subhierarchy in which a different inheritance strategy is applied.

引用资料

  • JPA 2.0 规范
    • 第 11.1.10 节“鉴别器列注释”

关于java - Eclipse 链接/JPA : Multiple @DiscriminatorColumn annotations for Entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3934134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com