JPA: Comparing LocalDateTime with CURRENT_TIMESTAMP

1,830 views
Skip to first unread message

Richard Richter

unread,
Apr 22, 2016, 8:25:57 AM4/22/16
to Querydsl
Hello

I have a field (validFrom) that is of type java.time.LocalDateTime (Java 8). I wanted to compare it with current local date time - and I can do it with LocalDateTime.now() without any problem. But this is client-side compare from the DB point of view.

I can still use this as a workaround, but I wanted to utilize JPQL function CURRENT_TIMESTAMP. Now there are two problems:
1) I mix local date time with Date that is more Instant like (absolute, not local). I don't know the impact of this problem and whether this is the blocker for my request.
2) Even if I had Instant, it is not java.util.Date and writing QEntity.validFrom.lt(DateTimeExpression.currentTimestamp()) would produce type incompatibility.

Is there any way how to convince Querydsl to generate expected JPQL? We have autoApply converter for LocalDateTime to Timestamp, so it should play well on the JPQL level, I just cannot get to compilable result. :-)

Thank you for any hint

Virgo

timowest

unread,
Apr 26, 2016, 1:32:02 PM4/26/16
to Querydsl
DateTimeExpression.currentTimestamp(Class<T>) should work in this case. You can use LocalDateTime.class to get the right expression.

Richard Richter

unread,
Apr 27, 2016, 11:18:59 AM4/27/16
to Querydsl
I completely missed that version with class parameter during API exploration, thank you very much, it works as advertised. :-)

Virgo
Reply all
Reply to author
Forward
0 new messages