use*_*057 6 polymorphism hibernate hql
我有一个类 A 和子类 B 和 C,它们具有不同的属性。我该怎么做: a from A a where ( a.class = B and a.specific-property-of-b = "y") or (a.class = C and a.specific-property-of-c ="z")
是否有可能让 hibernate 理解,当它是某个类的实例时,它可以访问它的特定属性,或者是不可能做这样的事情,我必须这样做:
a from A a where a.id in (select b.id from B b where b.specific-property-of-b = "y") 或 a.id in (select c.id from C c where c.specific- c 属性 = "z")
谢谢
您按照您的建议进行操作:
select a from A a
where (a.class = B and a.specificPropertyOfB = 'y')
or (a.class = C and a.specificPropertyOfC = 'z')
Run Code Online (Sandbox Code Playgroud)
唯一无法正常工作的事情(根据我的经验)是如果您在两个子类中定义两个具有相同名称的持久字段。
| 归档时间: |
|
| 查看次数: |
3110 次 |
| 最近记录: |