JPA 2.0 Typesafe Criteria API and Annotation Processing Howto
November 19th, 2009 by Gregory ShragoMaia build subsystem now recognizes Java Annotation Processors. Most of JPA 2.0 implementations are expected to make use of the Pluggable Annotation Processing API to automatically generate static metamodel classes. Here is a list of steps required to generate JPA 2.0 metamodel and keep it up-to-date with Hibernate Static Metamodel Generator. For the simplicity in this sample project the processor jar file is added to the module dependencies.
Now, Annotation processors will be run every time you invoke Make or Compile. Besides, there is a special menu item Process Annotations that does exactly what its name says. In this sample project I have added the generated directory to project sources to get completion in JPA 2.0 Typesafe Criteria API calls. Enjoy, Comment.

Tags: Annotation Processing, JPA 2.0, JSR 269, JSR-317, Make, Persistence

November 19th, 2009 at 10:58 am
Will this also work with annotation processors that emit modified existing classes? (Notably Project Lombok: http://projectlombok.org/ )
November 19th, 2009 at 11:20 am
I’ve tested the GetterSetterExample from the site.
The build part works fine but there is no resolve/completion for generated getters/setters as far as IDEA works with sources and not generated output.
November 19th, 2009 at 11:25 am
I have the same question as David Vallner, re:
http://projectlombok.org/features/Data.html
I’d like to have IDEA recognize the generated classes, and no longer give me red squiggles for calling generated methods (getters/setters in this case). Navigation to the generate class would be a bonus.
November 26th, 2009 at 7:47 am
I really appreciate that feature. However unless the generated classes are recognized by the IDEA and the generated sources are indexed and included into the type hierarchy it’s pretty useless
Guess this will come in a later milestone of Maia
November 26th, 2009 at 7:58 am
If your are unhappy with the JPA2 APT metamodel, you should given Querydsl a try. It provides a more compact, readable and typesafe metamodel :
http://source.mysema.com/display/querydsl/Querydsl
November 30th, 2009 at 8:39 am
The generated sources are indexed if the ‘generated’ directory is marked as a source folder in the corresponding module settings. Anyway Peter is right that currently IDEA does not do anything with the generated classes.
December 12th, 2009 at 11:48 am
Does anybody know how to debug annotation processors in IDEA?