JPQL的关联查询

一般情况下,直接使用mysql语句写关联语句,是join on 的形式,如下:

select * from tablea as a left join tableb as b on b.tablea_id = a.id

但是使用jpql写的时候就不能使用 join on 了,而是join where

select a from Tablea as a left join Tableb as b where b.tableaId = a.id

上面的那种写法,是因为tableb表 中有一个外键,是tablea 表的id

还有一种写法是在 实体中 对两个实体进行了关联映射 OneToMany、OneToOne,那么在进行关联查询的时候,就不需要写weher 语句了

select a from Tableb as b left join b.tablea as a

原创文章,欢迎转载,转载请注明出处

原文地址:https://www.cnblogs.com/acm-bingzi/p/jpqlJoin.html