Where is the annotation in sleep mode with the date as a condition

I was wondering if there is a way to use @Where(clause="")a set of things to bind to where is_active=1 AND expires_date <= new Date()in relation @OneToMany.

Something like that

@Where(clause="is_active=1 AND expires_date <=" + new Date())

Or can you only do this with constants?

This code will not work only for job search or if there is a way to do it. Thanks in advance.

+4
source share
3 answers

@Where.clause , .
- / , , filter, .
, - ; , .

+3

, . , .

Calendar rightNow = Calendar.getInstance();
Criteria criteria = session.createCriteria(yourclassname.class);
criteria.add(Restrictions.eq("is_active", 1));
criteria.add(Restrictions.le("expires_date", rightNow));
+1

, , sql, current_date postgresql:

@Where(clause="is_active=1 AND expires_date <= current_date")
0

Source: https://habr.com/ru/post/1545764/


All Articles