N. Doye
N. Doye

Reputation: 45

How to use Q Classes of Querydsl?

I want to use QueryDSL with JPA and I plugged in apt-maven successfully.

Pom.xml;

     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor </processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Also it generated the Q classes of domain classess successfully too but when I import com.buraku.netas.domain.QUser; , it throws an error and can't find Q classes.

Here's how my folder structure looks like after I run mvn install;

enter image description here

As you see Q classes are generated but what else should I do to use them?

Upvotes: 0

Views: 2648

Answers (1)

HanByul Lee
HanByul Lee

Reputation: 351

First, add implements QuerydslPredicateExecutor<User> to interface UserRepository.

Second, create a method which returns com.querydsl.core.types.Predicate and build a query(JPQL) using BooleanBuilder and Q-classes.

You might refer to my sample-jpa code on github.

jpa-sample-code

Upvotes: 2

Related Questions