JPQL:从超类连接确定子类类型?
我的问题与此非常相似:
我如何为超类编写 Hibernate Criteria 查询,并检查某个子类?
...,除了一件事:
- 我' m 使用 JPQL 查询 而不是 Hibernate Criteria API(尽管 Hibernate 仍然是 JPA 提供者)。
我引用的是一个超级表/实体类 (Round),它有两个子表/实体类(RankingRound 和 EliminationRound), 然后我创建一个 JOIN:
SELECT
...
??? AS is_ranking_round
...
FROM Group gr
JOIN gr.round rd
...
WHERE
有没有办法像 JPQL 中的上面那样找出 rd 实例的 round 类型? (我似乎无法将该标准转换为适用于 JPQL 的任何内容。)
My question is very similar to this one:
How can I write a Hibernate Criteria query, for a super-class, and check for a certain sub-class?
..., except for one thing:
- I'm using a JPQL query instead of the Hibernate Criteria API (still Hibernate as a JPA provider though)
I'm referencing a super table/entity class (Round) which has two sub tables/entity classes (RankingRound and EliminationRound). I then create a JOIN:
SELECT
...
??? AS is_ranking_round
...
FROM Group gr
JOIN gr.round rd
...
WHERE
Is there a way to find out the round type of the rd instance like the above in JPQL? (I don't seem to be able to translate the criterion to anything that works in JPQL.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这仅适用于 JPA 2.0。 JPA 1 没有 TYPE。
获取 java.lang.Class 类型:
将类的类型映射到字符串:
This works only with JPA 2.0 on. JPA 1 does not have TYPE.
To get type as java.lang.Class:
Mapping type of the class to string: