Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to compare dates, but SQLExpression.date(java.time.LocalDate) cannot be applied

Tags:

querydsl

I had earlier query like this:

public List<Human> findAllHumansWithPets(){

    QHuman human = QHuman.human;
    QPet pet = QPet.pet;

    JPAQuery query = new JPAQuery(entityManager);

    //Joda-Time
    LocalDate first = new LocalDate(1990, 01, 01);
    LocalDate last = new LocalDate(1990, 02, 01);

    return query.from(human)
            .innerJoin(human.pet, pet)
            .where(SQLExpressions.date(human.age).between(first.toDate(), last.toDate()))
            .list(order);
}

And it was working just fine. Now I updated age variable in my Human POJO to use java.time.LocalDate instead of org.joda.time.LocalDate. Querydsl didn't like that and is now complaining about parameter of SQLExpression.date.

    //java.time.LocalDate
    LocalDate first = LocalDate.of(1990, 01, 01);
    LocalDate last = LocalDate.of(1990, 02, 01);

    return query.from(human)
            .innerJoin(human.pet, pet)
            .where(SQLExpressions.date(human.age).between(first, last))
            .list(order);
    }

DateTimeExpression<java.lang.Comparable> in SQLExpressions cannot be applied to com.mysema.query.types.path.DatePath<java.time.LocalDate>

I can't seem to find any workaround about this issue. Would be nice to prevent going back to Joda-Time. Any suggestions?

like image 459
PineappleChunks Avatar asked Nov 06 '15 15:11

PineappleChunks


1 Answers

DateExpression.currentDate(LocalDate.class).between(..., ...)
DateExpression.currentDate(LocalDateTime.class).between(..., ...)
like image 192
Marcus Vinícius Voltolim Avatar answered Oct 03 '22 10:10

Marcus Vinícius Voltolim