【问题标题】:Table per subclass (without using a discriminator)每个子类的表(不使用鉴别器)
【发布时间】:2015-10-21 14:53:07
【问题描述】:
【问题讨论】:
标签:
hibernate
discriminator
【解决方案1】:
如果您查看查询,它将有某种 switch 语句,如下所示
select
account0_.id as id1_9_,
account0_.balance as balance2_9_,
account0_1_.checkLimitAmount as checkLim1_10_,
account0_2_.atmLimit as atmLimit1_11_,
case
when account0_1_.id is not null then 1
when account0_2_.id is not null then 2
when account0_.id is not null then 0
end as clazz_
from
INHERITANCE_JTND_ACCOUNT account0_
left outer join
INHERITANCE_JTND_CHECKING_ACCOUNT account0_1_
on account0_.id=account0_1_.id
left outer join
INHERITANCE_JTND_SAVINGS_ACCOUNT account0_2_
on account0_.id=account0_2_.id
所以它只做一个查询。 Hibernate 然后使用clazz_ 列来确定要实例化的内容。上面的查询来自 HSQLDB,对于其他数据库引擎可能会有所不同。
打印 JPA/Hibernate 生成的 SQL 语句(至少在您的本地环境中)通常是个好主意,因为有时您会对它生成的 DML 感到惊讶。