How to lie down to join two unrelated objects with JPA criteria?

using JPA 2.1 and hibernate 5.1.x, this is possible with JPQL

select s.lowerBound,
l.status
...
from Serie s
left join Line l on
s.lowerBound between l.lineStart and l.lineEnd

how do i write this using api criterion? i tried this

Root<Serie> serieRoot = query.from(Serie.class);
Root<Line> lineRoot query.from(Line.class);
query.where(criteriaBuilder.between(s.get("lowerBound"), l.get("lineStart"), s.get("lineEnd")))

but this does not allow me to indicate its left join.

+4
source share
1 answer

What you do with your Criteria request, you cannot specify this as a left join because it is not a completely left join. You have only a few roots in your query and according to the Hibernate documentation , which uses Cartesian products, however with a left join you get zeros if there are no matches.

, , , , API . , JPQL SQL .

+1

Source: https://habr.com/ru/post/1667689/


All Articles