【问题标题】:Want to compare dates, but SQLExpression.date(java.time.LocalDate) cannot be applied想比较日期,但是不能应用 SQLExpression.date(java.time.LocalDate)
【发布时间】:2016-02-07 18:55:16
【问题描述】:

我之前有这样的查询:

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);
}

而且它工作得很好。现在我更新了 Human POJO 中的 age 变量以使用 java.time.LocalDate 而不是 org.joda.time.LocalDate。 Querydsl 不喜欢这样,现在抱怨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);
    }
SQLExpressions 中的

DateTimeExpression 不能应用于 com.mysema.query.types.path.DatePath

我似乎找不到任何解决此问题的方法。最好能阻止回到 Joda-Time。有什么建议?

【问题讨论】:

  • 你使用哪个 Querydsl 版本?
  • 3.6.9 这是我可以从 mvnrepository.com 找到的最新版本
  • 哦,我找到了4.0.6版本(他们在不同的groupId下)并升级到它。它仍然说同样的,只是路径改变了。 in SQLExpressions cannot be applied to com.querydsl.core.types.dsl.DatePath&lt;java.time.LocalDate&gt;

标签: querydsl


【解决方案1】:
DateExpression.currentDate(LocalDate.class).between(..., ...)
DateExpression.currentDate(LocalDateTime.class).between(..., ...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多