In MySQL, This works and I want to achieve equivalent with hibernate:
Select * from A a left join B b on a.id=b.id AND b.lenght=20
There is OneToMany()
: Class A
contains List <B> b
With hibernate I got stuck on that:
//the ON clause comes from the mapping's join columns and is handled automatically
@Query(Select a from A a left join a.b c)
but I dont know how to add this part AND b.lenght=20
Hot to translate it to JPQL with JPA?
You can add your condition in the join clause using the WITH keyword
Select a from A a left join a.b with b.lenght = 20
... assuming lenght
is a field in B, not the length function.
[ https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/queryhql.html]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.