Skip to content
Advertisement

JPQL query for parameter in list

I have two JPA-entities:

JavaScript

and I tried to write a JPQL query to extract requests that:

  • If the parameter is false then extract all requests with empty hotelBookings and all requests where every booking have parameter jointCheckIn is set to false
  • If a parameter is true then extract all requests that have one or more bookings with jointCheckIn is set to true

I wrote something like this

select e from nk$BusinessTripRequest e join e.hotelBookings hb
where (true = ? and e.hotelBookings is not empty and hb.jointCheckIn = true)
or (false = ? and e.hotelBookings is empty)

It works well when parameter is true because of the first condition. But I can’t write a working condition for false parameter

Advertisement

Answer

solution suggested from comments

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement