HQL 查询根据多个要求检查列表的每个项目

HQL query checking each item of list against multiple requirements

我想根据实体列表的内容过滤查询。我不只是想检查这个列表中是否有东西,我想在函数式编程中有一个 'predicate',因为 'predicate' 是 hql 中的其他东西,所以研究起来很有挑战性。

所以基本上

list.filter(x -> x > 100 and x < 150)

是我想要的hql。

// This query is pseudocode of what I want to achieve
// keywords ANY_OF, CONFORMS_TO are made up syntax in the code below
public List<PainTracker> getTrackersInCurrentlyActive() {
    String query = "FROM PainTracker AS tracker WHERE ANY_OF tracker.timePeriods AS tp CONFORMS_TO tp.startTime < :currentTime AND tp.endTime > :currentTime)";
    TypedQuery<ParkedParking> q = entityManager.createQuery(query, ParkedParking.class);
    q.setParameter("currentTime", new Date());
    return q.getResultList();
}

//PainTracker has this field 
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "pain_time_periods",
        joinColumns = @JoinColumn(name = "pain_tracker"),
        inverseJoinColumns = @JoinColumn(name = "time_periods"))
private List<TimePeriod> timePeriods;

@Entity
@Table(name = "time_period")
public class TimePeriod {
// This table have startTime and endTime

我研究过使用 expression operator ANY (subquery),但我不明白它是如何实现的。我需要将我的整个表达式作为对列表中每个项目的检查。

HQL 有这方面的东西吗?它叫什么?

尝试使用以下查询:

select distinct p from PainTracker p
join fetch p.timePeriods tp
where tp.startTime < :currentTime and tp.endTime > :currentTime

另请参阅休眠文档的 this section