select x from X x where x.a.id = :a_id
--> 始终选择 0 个对象
为什么上面的 JPQL 语句不起作用,但下面的语句起作用?
select a from A a where a.id = :a_id
--> a_obj
select x from X x where x.a = :a_obj
--> 始终选择正确的对象数量
两个查询在执行过程中都没有抛出异常,但获得的结果数量不同。
谢谢
更新
我使用连接尝试了以下查询:
select x from X x, x.a a where x.a.id = :a_id
--> TopLink 意外令牌异常
这:
select x from X x JOIN x.a a where a.id = :a_id
->始终选择正确的对象数量
通过后一个查询,我已经解决了手头的初始问题。但是,现在我有两个应该可以工作的查询,但由于某种原因没有。
select x from X x where x.a.id = :a_id
--> 始终选择 0 个对象
select x from X x, x.a a where x.a.id = :a_id
--> 意外令牌的 TopLink 异常
有没有其他人遇到过类似的行为?