Hibernate使用错误类型的子类

时间:2016-08-07 10:14:47

标签: java oracle hibernate jpa named-query

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

@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'周围的标签手动触发此查询时,查询运行正常。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

试试这个 你可以用@inheritance注释定义超类

@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 {

}