querydsl/querydsl-jpa
Jan-Willem Gmelig Meyling ff3d0c8a17 Fix various issues caused by invalid constant assumptions
Reverts #2354
Fixes #2326
Fixes #2816
Fixes #1413
Fixes #1429
Closes #2000
2021-06-08 16:34:06 +02:00
..
etc Normalize line endings to lf 2015-12-13 22:55:32 +01:00
src Fix various issues caused by invalid constant assumptions 2021-06-08 16:34:06 +02:00
pom.xml Bump org.jetbrains:annotations dependency 2021-06-03 17:58:27 +02:00
README.md Switch from Slf4j to JUL to reduce transitive dependencies 2021-01-17 15:54:11 +01:00

Querydsl JPA

The JPA module provides integration with the JPA 2 persistence API.

Maven integration

Add the following dependencies to your Maven project :

<dependency>
  <groupId>com.querydsl</groupId>
  <artifactId>querydsl-jpa</artifactId>
  <version>${querydsl.version}</version>
</dependency>

And now, configure the Maven APT plugin :

<project>
  <build>
    <plugins>
      ...
      <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>
        <dependencies>
          <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
          </dependency>
        </dependencies>
      </plugin>
      ...
    </plugins>
  </build>
</project>

The JPAAnnotationProcessor finds domain types annotated with the javax.persistence.Entity annotation and generates query types for them.

If you use Hibernate annotations in your domain types you should use the APT processor com.querydsl.apt.hibernate.HibernateAnnotationProcessor instead.

Run clean install and you will get your Query types generated into target/generated-sources/java.

If you use Eclipse, run mvn eclipse:eclipse to update your Eclipse project to include target/generated-sources/java as a source folder.

Now you are able to construct JPQL query instances and instances of the query domain model.

Querying

Querying with Querydsl JPA is as simple as this :

QCustomer customer = QCustomer.customer;
JPAQuery<?> query = new JPAQuery<Void>(entityManager);
Customer bob = query.select(customer)
  .from(customer)
  .where(customer.firstName.eq("Bob"))
  .fetchOne();

For more information on the Querydsl JPA module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02.html#jpa_integration