gpt4 book ai didi

java - Hibernate 生成子类的 @discriminatorvalues 类型错误的查询

转载 作者:行者123 更新时间:2023-11-30 07:13:22 25 4
gpt4 key购买 nike

我有具有连接类型的实体的继承关系。

@Entity
@Table(name = "MSM_SUBSCRIPTION")
@DiscriminatorColumn(name = "SUBSCRIPTIONTYPE", discriminatorType = DiscriminatorType.STRING, length = 100)
class subscription {
}


@DiscriminatorValue("com.xxx.XXXSubscription")
@Table(name = "XXX")

public class XXXSubscription extends Subscription implements Serializable {

}

当我尝试使用命名查询时,例如

SELECT s.class AS subscriptiontype,
FROM
Subscription s

它会产生以下查询

select

case

when s1_.subscriptionId is not null then com.xxx.XXXSubscription
when s.subscriptionId is not null then 'Subscription'
end AS subscriptiontype,

from

MSM_SUBSCRIPTION s

left outer join
XXXSubscription s1_
on s.subscriptionId=s6_.subscriptionId

这会引发如下错误。

-ORA-00904: "COM"."xxx"."MMSSUBSCRIPTION": invalid identifier

正如我所注意到的,生成的查询中的 case 语句周围没有标签,在使用 DiscriminatorValue“com.xxx.XXXSubscription”周围的标签手动触发此查询时,查询运行良好。

有人可以帮忙吗?

最佳答案

试试这个您可以使用@inheritance注释定义父类(super class)

@Entity
@Table(name = "MSM_SUBSCRIPTION")
**@Inheritance(strategy = InheritanceType.SINGLE_TABLE)**
@DiscriminatorColumn(name = "SUBSCRIPTIONTYPE", discriminatorType = DiscriminatorType.STRING, length = 100)
class subscription {
}


@DiscriminatorValue("com.xxx.XXXSubscription")
@Table(name = "XXX")

public class XXXSubscription extends Subscription implements Serializable {

}

关于java - Hibernate 生成子类的 @discriminatorvalues 类型错误的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38813099/

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