(B类扩展A类,A具有“TABLE_PER_CLASS”的@Inheritance策略。)
我现在只查询A.在查询中不应该涉及B。
HQL看起来不错:
select generatedAlias0 from A as generatedAlias0 where ( generatedAlias0.id in (1, 2, 3) ) and ( generatedAlias0.dateDeleted is null )
......不知何故,Hibernate将其转化为:
-- simplified for readability sake
SELECT
*
FROM (
SELECT * FROM A
UNION ALL SELECT * FROM B -- <-- ???
)
WHERE .....
为什么呢? STAHP!
(删除@Inheritance注释时,UNION已经消失,B列引用仍然存在,使最终查询无效。)