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

I had a previous request:

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 worked fine. Now I updated the variable agein my human POJO to use java.time.LocalDate instead of org.joda.time.LocalDate. Querydsl did not like it, and now complains about the parameter 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 do not seem to have found a workaround about this issue. It would be nice to stop you from returning to Joda-Time. Any suggestions?

+4
source share

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


All Articles