简体   繁体   中英

Can we use a relational operator with list of values in JPQL + hibernate?

My entity looks like this:

@Entity
public class interval {
       private Integer id;
       private LocalDateTime intervalDate;
}

I want to write a JPQL query to fetch all the intervals whose interval date is greater than a list of dates I pass to the query.

Something like this:

SELECT i from Interval i where i.intervalDate >= :listOfDates

where listOfDates is List<LocalDateTime> listOfDates = new ArrayList<>();

You will have to create a dedicated query per use case. Like suggested in the comments, one query with

SELECT i from Interval i where i.intervalDate >= :listOfDatesMax

where the listOfDatesMax parameter is set to the maximum from your list. And

SELECT i from Interval i where i.startTime >= :startTimeListMax And i.endTime <= :endTimeListMin

where again the startTimeListMax and endTimeListMin parameters are set to the maximum/minimum from the respective list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM