【问题标题】:Mysema Querydsl: There's no JPAQuery#list() methodMysema Querydsl:没有 JPAQuery#list() 方法
【发布时间】:2016-01-11 04:59:52
【问题描述】:

Mysema Querydsl 使用的一些在线示例依赖于 JPAQuery#list() 方法,例如this stackoverflow answer 包含一个 GROUP BY / COUNT 聚合示例。它在整个official documentation 中也被提及。

但是,我只是在 JPAQuery 类上看不到这种方法。它不会出现在 IDE 的自动完成中,也不会出现在 Maven 下载的 JAR 文件中。

我已将这些依赖项添加到我的 Maven 项目中:

<dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <version>4.0.4</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <version>4.0.4</version>
</dependency>

为什么JPAQuery#list() 方法不存在?

【问题讨论】:

    标签: maven querydsl


    【解决方案1】:

    当 Querydsl 从 3.x 升级到 4.x 行时,方法 JPAQuery.list 被删除。由于您使用的是 4.0.4 版本,因此该方法不再可用。

    据我阅读release notes 了解到,第 4 版在代码库中引入了许多重大更改,这些更改破坏了旧代码。你有两个选择:

    • 降级到 3.x 行的最后一个版本,即 3.6.8 并使用list 方法
    • 保留版本 4.0.4 并改用fetch 方法。查看 this GitHub issue 了解更改列表。

    【讨论】:

    • 谢谢图纳基。这就是我害怕的。我想我会尝试坚持使用 4.0.4 并弄清楚如何升级我的查询。 @Mysema people:有人介意更新参考文档吗?
    • 感谢您的提醒。将被修复github.com/querydsl/querydsl/pull/1626
    • 接受参数的列表方法怎么样(在 mysema 中)。 fetch() 不带任何参数。
    • @Tisha 我想是select(...).fetch(), see here for example
    • 好的,我移到了 com.querydsl 包,但即使这样似乎也不起作用 - jpaQuery.from(qGroup, qType, qCountry) -->
    猜你喜欢
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 2017-04-14
    • 2014-09-12
    • 1970-01-01
    • 2013-04-25
    • 1970-01-01
    相关资源
    最近更新 更多