如何在JPQL中访问OnetoMany连接表?

时间:2011-07-24 23:28:10

标签: jpa jpql

我想在JPQL中编写一个复杂的lttl查询,我可以访问OneToMany Join表。我得到QuerySyntaxException:未映射Pan_PanRes。

QUERY -

query = "SELECT p FROM Pan p WHERE p.id IN " +
            "(SELECT p_id FROM Pan_PanRes p_prs WHERE prs_id IN " +
            "(SELECT r.id FROM PRS r where r.pant = :pant))"+                       
            " ORDER BY pr.clD"

我尝试在MYSQL中实现这个概念。它工作正常。所以我知道我没有以正确的方式调用连接表。那应该怎么称呼呢?

我想添加工作正常的MYSQL语句 -

mysql> select * from pan where id not in 
(select pan_id from pan_panres where panres_id in 
(select id from panres where pant_id = 3));

...谢谢

1 个答案:

答案 0 :(得分:2)

自己解决了 -

query = "SELECT p FROM Pan p WHERE p.id IN " +
            "(SELECT p.id FROM p.panRes prs WHERE id IN " +
            "(SELECT r.id FROM PanRes r where r.pant = :pant))"+                       
            " ORDER BY pr.clD"

其中panRes是我在Pan Class中使用的oneToMany变量名。