Querydsl maven compilation error: QClass.class does not exist

3,700 views
Skip to first unread message

Frey Zheng

unread,
Apr 13, 2014, 4:53:45 AM4/13/14
to quer...@googlegroups.com
Hi,

I am new to Querydsl and trying to use it in a simple test project. I followed the official tutorial to configure my 

pom.xml, then mvn clean install was able to generated the Q Classes under target/generated-sources/java. But I got the 

error below:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project 

spring-jqgrid-tutorial: Compilation failure

[ERROR] /D:/Project/spring-jqgrid-tutorial/src/main/java/org/krams/controller/UserController.java:[92,62] package 

QUser.user does not exist
I think the root cause is the generated Q class source files were not compiled automatically into binary class files. I 

did verify there are no QUser.class under my project directory. I also tried to use build-helper-maven-plugin to add 

target/generated-sources/java as a source folder and specify target/generated-sources/java as an additional source root in 

apt-maven-plugin configuration. But I got no luck.

Here is my pom.xml

<properties>
    <querydsl.version>3.3.2</querydsl.version>
    <maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
    <maven.apt.plugin.version>1.1.1</maven.apt.plugin.version
    <maven.build.helper.plugin.version>1.8</maven.build.helper.plugin.version>
<properties>

<dependencies>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>${querydsl.version}</version>
        </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>${querydsl.version}</version>
        <scope>provided</scope>
    </dependency>
 <dependencies>

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.plugin.version}</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
                <version>${maven.build.helper.plugin.version}</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>target/generated-sources/java</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>${maven.apt.plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                        <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                        <additionalSourceRoots>
                            <additionalSourceRoot>target/generated-sources/java</additionalSourceRoot>
                        </additionalSourceRoots>
                    </configuration>
                </execution>
            </executions>
        </plugin>
<plugins>


And here is the generated QUser.java

package org.krams.domain;

import static com.mysema.query.types.PathMetadataFactory.*;

import com.mysema.query.types.path.*;

import com.mysema.query.types.PathMetadata;
import javax.annotation.Generated;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PathInits;


/**
 * QUser is a Querydsl query type for User
 */
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QUser extends EntityPathBase<User> {

    private static final long serialVersionUID = -1712499619L;

    private static final PathInits INITS = PathInits.DIRECT2;

    public static final QUser user = new QUser("user");

    public final NumberPath<Integer> age = createNumber("age", Integer.class);

    public final StringPath firstName = createString("firstName");

    public final NumberPath<Long> id = createNumber("id", Long.class);

    public final StringPath lastName = createString("lastName");

    public final StringPath password = createString("password");

    public final QRole role;

    public final StringPath username = createString("username");

    public QUser(String variable) {
        this(User.class, forVariable(variable), INITS);
    }

    public QUser(Path<? extends User> path) {
        this(path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
    }

    public QUser(PathMetadata<?> metadata) {
        this(metadata, metadata.isRoot() ? INITS : PathInits.DEFAULT);
    }

    public QUser(PathMetadata<?> metadata, PathInits inits) {
        this(User.class, metadata, inits);
    }

    public QUser(Class<? extends User> type, PathMetadata<?> metadata, PathInits inits) {
        super(type, metadata, inits);
        this.role = inits.isInitialized("role") ? new QRole(forProperty("role"), inits.get("role")) : null;
    }

}


Appreciate your help and comments. I can provide more information if required.

timowest

unread,
Apr 13, 2014, 7:15:11 AM4/13/14
to quer...@googlegroups.com
Hi.

The additionalSourceRoots part seems unnecessary in the apt-maven-plugin config.

Also does it work better without the build-helper-maven-plugin config?

Br,
Timo

Frey Zheng

unread,
Apr 13, 2014, 7:28:03 AM4/13/14
to quer...@googlegroups.com
Hi Timo,

Thanks for the reply.
I got the same error after I removed the additionalSourceRoots and the build-helper-maven-plugin config.
But if I remove the below part from UserController.java, which is the only reference to QUser, I can get the compiled file: QUser.class

Page<User> users = null;
if (qUsername != null) 
users = repository.findAll(QUser.user.username.like(qUsername), pageRequest);

Any idea?

Regards,
Frey

Timo Westkämper

unread,
Apr 13, 2014, 7:30:16 AM4/13/14
to Querydsl on behalf of Frey Zheng
Hi.

Do you get a compilation failure or just a warning?

Timo


--
You received this message because you are subscribed to the Google Groups "Querydsl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to querydsl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com


Frey Zheng

unread,
Apr 13, 2014, 7:38:35 AM4/13/14
to quer...@googlegroups.com
Hi,
It was a failure.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.009 s
[INFO] Finished at: 2014-04-13T16:58:46+08:00
[INFO] Final Memory: 21M/230M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
1:compile (default-compile) on project spring-jqgrid-tutorial: Compilation failu
re
[ERROR] /D:/Project/spring-jqgrid-tutorial/src/main/java/org/krams/controller/Us
erController.java:[92,62] package QUser.user does not exist
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
eption

On Sunday, April 13, 2014 7:30:16 PM UTC+8, Timo Westkämper wrote:
Hi.

Do you get a compilation failure or just a warning?

Timo

Timo Westkämper

unread,
Apr 13, 2014, 7:44:50 AM4/13/14
to Querydsl on behalf of Frey Zheng
If the code generation works, maybe the source is broken? Do you import the QUser class correctly?

Frey Zheng

unread,
Apr 13, 2014, 7:57:21 AM4/13/14
to quer...@googlegroups.com
The imports should be correct. See below. 

package org.krams.controller;

import java.util.List;
import org.krams.domain.Role;
import org.krams.domain.User;
import org.krams.domain.QUser;
import org.krams.repository.UserRepository;
import org.krams.response.JqgridResponse;
import org.krams.response.StatusResponse;
import org.krams.response.UserDto;
import org.krams.service.UserService;
import org.krams.util.JqgridFilter;
import org.krams.util.JqgridObjectMapper;
import org.krams.util.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

Now I am thinking if it is the query causing the problem: 
users = repository.findAll(QUser.user.username.like(qUsername), pageRequest);

I am using spring data jpa. repository here is an instance of UserRepository, which extends QueryDslPredicateExecutor.

On Sunday, April 13, 2014 7:44:50 PM UTC+8, Timo Westkämper wrote:
If the code generation works, maybe the source is broken? Do you import the QUser class correctly?

Timo Westkämper

unread,
Apr 13, 2014, 8:01:49 AM4/13/14
to Querydsl on behalf of Frey Zheng
I am out of ideas. Could you maybe provide a minimal example project on github to verify your issue?

Code generation works, but the generated sources are not compiled under target/classes?

Frey Zheng

unread,
Apr 13, 2014, 8:10:15 AM4/13/14
to quer...@googlegroups.com
Trying to build the project from scratch again. If it fails again, I will upload my project on github.
Thanks.


On Sunday, April 13, 2014 8:01:49 PM UTC+8, Timo Westkämper wrote:
I am out of ideas. Could you maybe provide a minimal example project on github to verify your issue?

Code generation works, but the generated sources are not compiled under target/classes?

Frey Zheng

unread,
Apr 14, 2014, 11:19:28 AM4/14/14
to quer...@googlegroups.com
Update:
I built everything from scratch again and finally Querydsl is working.
I think this problem was probably caused by incompatible versions of spring data jpa and querydsl.
Now I am using spring data jpa 1.3.2.RELEASE and querydsl 2.8.0., everything works perfectly.
P.S. I removed the additionalSourceRoots and the build-helper-maven-plugin config. They are unnecessary.

Timo Westkämper

unread,
Apr 14, 2014, 11:22:33 AM4/14/14
to Querydsl on behalf of Frey Zheng
Good. You might want to consider upgrading Querydsl. 2.8.0 is quite old.

Frey Zheng

unread,
Apr 15, 2014, 9:46:08 AM4/15/14
to quer...@googlegroups.com
Update spring-core, spring-data-jpa, querydsl to newest versions. All works fine!
spring-core: 4.0.3.RELEASE
spring-data-jpa: 1.5.1.RELEASE
querydsl: 3.3.2


On Monday, April 14, 2014 11:22:33 PM UTC+8, Timo Westkämper wrote:
Good. You might want to consider upgrading Querydsl. 2.8.0 is quite old.
Reply all
Reply to author
Forward
0 new messages