I have three integer values of two pairs.
I would like to use this as a list of IN in the WHERE clause.
(2019, 5) (2019, 6) (2019, 7)
I want to use the above two-pair list in a query like this:
SELECT
*
FROM
WEEK_REPORT A
WHERE
A.user_id IN ('test2','test5' ) AND
(A.year, A.week_no) IN ((2019,4),(2019,5),(2019,6));
To that end, I wrote the source as follows:
// lastYear=2019, lastWeekNo=4
Tuple t = JPAExpressions.select(Expressions.constant(lastYear), Expressions.constant(lastWeekNo))
.from(weekReport)
.fetchOne();
// currentYear=2019, currentWeekNo=5
Tuple t2 = JPAExpressions.select(Expressions.constant(currentYear), Expressions.constant(currentWeekNo))
.from(weekReport)
.fetchOne();
// nextYear=2019, nextWeekNo=4
Tuple t3 = JPAExpressions.select(Expressions.constant(nextYear), Expressions.constant(nextWeekNo))
.from(weekReport)
.fetchOne();
return queryFactory
.select(weekReport)
.from(weekReport)
.where(weekReport.user.eq(user)
.and(Expressions.list(weekReport.year, weekReport.weekNo).in(t, t2, t3)))
.fetch();
However, the correct result is not output and an error occurs.
java.lang.UnsupportedOperationException: null
at com.querydsl.jpa.JPASubQuery.fetchOne(JPASubQuery.java:66) ~[querydsl-jpa-4.1.4.jar:na]
I looked it up in the official document but it does not come out.
Is there a way?
Thank you.
how about to pass a list of tuples as one parameter
List<Tuple> params = ...
params = [(2019,4),(2019,5),(2019,6)]
return queryFactory
.select(weekReport)
.from(weekReport)
.where(weekReport.user.eq(user)
.and(Expressions.list(weekReport.year, weekReport.weekNo).in(params)))
.fetch();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With