2010-10-01

Using Querydsl In Eclipse

Querydsl usage in Eclipse is now easier than ever. Since Querydsl 2.0 we have improved APT support in Querydsl to support incremental code generation in IDEs. We have also improved the release bundles to streamline the APT configuration in Java IDEs like Eclipse.

The APT usage improvements affect the JPA, JDO and MongoDB modules. Instead of a set of screenshots we have prepared a screencast to showcase the new APT features in Querydsl in an Eclipse context.

To enable APT usage in Eclipse you need to
  • set the Enable annotation processing checkbox via Properties > Java Compiler > Annotation Processing,
  • add the APT option defaultOverwrite = true if you are using Eclipse Helios and
  • set the Factory Path to one of the apt-one-jar files included in your release bundle.

The screencast uses the Querydsl JPA module in combination with Hibernate and shows the creation of a Java project, the creation of two simple domain types and the creation of a minimal demo service which presents the simplicity of Querydsl query usage.

5 comments:

  1. I followed your instructions for Eclipse Helios, but I get an exception:

    java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundEnvImpl.getElementsAnnotatedWith(RoundEnvImpl.java:122)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundEnvImpl.getElementsAnnotatedWith(RoundEnvImpl.java:186)
    at com.mysema.query.apt.DefaultConfiguration.(DefaultConfiguration.java:111)
    at com.mysema.query.apt.jpa.JPAConfiguration.(JPAConfiguration.java:57)
    at com.mysema.query.apt.hibernate.HibernateConfiguration.(HibernateConfiguration.java:33)
    at com.mysema.query.apt.hibernate.HibernateAnnotationProcessor.createConfiguration(HibernateAnnotationProcessor.java:28)
    at com.mysema.query.apt.jpa.JPAAnnotationProcessor.process(JPAAnnotationProcessor.java:45)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:110)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:134)
    at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:836)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:428)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:364)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:178)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:301)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:60)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:173)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:629)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:172)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:203)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:255)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:258)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:362)
    at org.eclipse.core.internal.resources.Project$1.run(Project.java:545)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
    at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:524)
    at org.eclipse.core.internal.resources.Project.build(Project.java:115)
    at org.eclipse.jdt.internal.ui.util.CoreUtility$BuildJob.run(CoreUtility.java:160)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

    ReplyDelete
  2. Sorry for the late reply. Here is a related ticket : https://bugs.launchpad.net/querydsl/+bug/837998

    ReplyDelete
  3. The Q* classes are generated correctly but when the project gets cleaned, a lot of errors appear saying that the imports cannot be resolved (it's validating my code before generating the EntityPath classes).

    Can I configure Eclipse to don't delete Q classes or to process imports after Q classes are created?

    The only way I've found to get rid of these messages is open and save the files but I can't tell that to my team :(

    ReplyDelete
  4. How can I test this?
    I use JPA QueryDsl CDI JSF ...arquilian and maven, when I don't use QueryDsl my tests run good, but when I use QueryDsl my test has errors

    ReplyDelete
  5. Hi, I'm trying to include querydsl in Spring STS IDE and trying to add it via this link http://ilx.github.com/m2e-querydsl/repository/0.0.5/ but to no avail. Any pointers please.

    ReplyDelete