10

Some online examples for Mysema Querydsl usage rely on the JPAQuery#list() method, e.g. this stackoverflow answer containing a GROUP BY / COUNT aggregate example. It is also referred to throughout the official documentation.

However, I do just not see this method on the JPAQuery class. It doesn't show up in the IDE's autocomplete, and it's not present in the JAR file downloaded by Maven.

I have added these dependencies to my Maven project:

<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>

Why is the JPAQuery#list() method not present?

Community
  • 1
  • 1
SputNick
  • 1,231
  • 5
  • 15
  • 26

1 Answers1

9

The method JPAQuery.list was removed when Querydsl upgraded from the 3.x to the 4.x line. Since you are using version 4.0.4, this method is no longer available.

As I understand from reading the release notes, version 4 introduces a lot of major changes in the code base that breaks older code. You have two options:

  • downgrade to the last version of the 3.x line, which 3.6.8 and use the list method
  • keep version 4.0.4 and use the fetch method instead. Take a look at this GitHub issue for the list of changes.
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Thank you Tunaki. That's what I was afraid of. I think I'll try to stick with 4.0.4 and figure out how to upgrade my queries. @Mysema people: Would anyone mind updating the reference doc? – SputNick Oct 13 '15 at 13:38
  • Thanks for the heads up. Will be fixed https://github.com/querydsl/querydsl/pull/1626 – Timo Westkämper Oct 31 '15 at 19:02
  • What about the list method that takes a parameter (in mysema). fetch() does not take any parameters. – Tisha Feb 28 '17 at 06:19
  • 3
    @Tisha I think, it is `select(...).fetch()`, [see here for example](https://github.com/querydsl/querydsl/pull/1217/files#diff-7e7ef10caa3efd492957e81c151a23efL122). – Tunaki Feb 28 '17 at 08:03
  • Ok, I moved to com.querydsl package but even this doesn't seem to be working - jpaQuery.from(qGroup, qType, qCountry) --> – Tisha Feb 28 '17 at 10:40
  • @Tisha I'm afraid I don't know here, perhaps you should ask a separate question. – Tunaki Feb 28 '17 at 11:01