开发者

How to access a OnetoMany join table in JPQL?

开发者 https://www.devze.com 2023-03-22 19:47 出处:网络
I want to write a lttl complicated query in JPQL where i access a OneToMany Join table. I get QuerySyntaxException: Pan_PanRes is not mapped.

I want to write a lttl complicated query in JPQL where i access a OneToMany Join table. I get QuerySyntaxException: Pan_PanRes is not mapped.

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"

i tried implementing this concept in MYSQL. It works fine. So i know i am 开发者_如何学编程not calling the join table in right way. How should it be called then?

I would like to add MYSQL statement which works fine -

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));

Thanks...


Solved it myself -

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"

Where panRes is the oneToMany variable name i have used in Pan Class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号