我希望将以下 SQL 转换为 JPQL:
SELECT *
FROM rooms
WHERE NOT EXISTS
(
SELECT *
FROM booking, booking_has_rooms
WHERE rooms.number=booking_has_rooms.rooms_number AND
booking.booking_id=booking_has_rooms.booking_booking_id AND
:date BETWEEN booking.checkin AND booking.checkout
);
到目前为止,我有这个:
SELECT rooms
FROM Rooms rooms
WHERE NOT EXISTS
(
SELECT bk
FROM Booking b
JOIN b.roomsCollection bk
WHERE :date BETWEEN b.checkin AND b.checkout
)
如果在指定日期没有预订,它将正确返回所有房间。但是,如果任何预订在指定日期 - 它根本不会返回任何房间。