Wpis z mikrobloga

Mam 2 encje JPA w relacji one-to-many - Seat i Booking. Chciałbym pobrać Seat po id z Bookings ze statusem "ACTIVE'. Jeśli Booking nie miałby takich Seats to powinno zostać zwrócone Seat z pustą listą Bookings.

Takie query działa w konsoli do SQL:

select * from seats s left join bookings b on b.seat_id=s.id and b.status='ACTIVE' where s.id=1
Przerobiłem je na query do Spring Data JPA:

@query("select s from Seat s left join fetch s.bookings b on b.seat.id=s.id and b.status='ACTIVE' where s.id = :seatId")
Ale dostaje taki błąd:

org.hibernate.hql.internal.ast.QuerySyntaxException: with-clause not allowed on fetched associations; use filters
#java #spring #naukaprogramowania #programowanie
  • 2
@Nofenak: Musisz najpewniej użyć podzapytania (piszę z palca więc na pewno nie pójdzie od razu). select * from seats s left join (select seatid from bookings b where and b.status='ACTIVE') as bo on bo.seatid=s.id where s.id=1