0

I have this query:

@Query("SELECT p FROM Route p JOIN FETCH p.places pl WHERE pl.city = (:city)")
public List<Route> findByPlaces_City(@Param("city")City city);

It fetch me only places where places.coty = city

And what I need is: if any place from route have city like argument get that route with fetched all places from that route;

0

2 Answers 2

1

Such a query is not allowed by JPA, because you may not apply restrictions on a fetched join.

But you can simply use an inner join to apply your restriction, and another fetch join to load the cities:

select distinct r from Route r 
inner join r.places p
left join fetch r.places
where p.city = :city
Sign up to request clarification or add additional context in comments.

Comments

1

Try with left join fetch

@Query("SELECT p FROM Route p LEFT JOIN FETCH p.places pl WHERE pl.city = (:city)")

1 Comment

unfortunately same thing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.