Switching Annotation Preprocessors for JPA Meta Model Generation in Eclipse

In case you haven't noticed, Eclipse doesn't have the most stable annotation preprocessor. I use Hibernate as my persistance provider but I've experienced problems with Hibernate's meta model generation jar - at least when used in Eclipse. In need of a solution, a colleague turned me onto OpenJPA for the meta model generation and still use Hibernate as the actual persistance provider. Open JPA is a bit too strict as a provider still but works like a charm for metamodel generation. To set the annotation processor in Eclipse, follow the steps below. I'll set it to OpenJPA, but you can use any one you want.

  1. Right click the project in the project explorer and go to Properties...
  2. In the left side navigation area, select Annotation Processing under Java Compiler.
  3. You'll want to check Enable Project Specific Settings, then Enable annotation processing
  4. Select the generated source directory - I build with Maven, so I've selected the standard Maven location.
  5. Annotation Processor Screenshot - Spring Source Toolkit
  6. You can see from the the screenshot that I have a single processor option openjpa.metamodel=true. You'll need to set this if you're planning to use OpenJPA for your metamodel generation. Hibernate does not require this. See the documentation of your processor if using something other than OpenJPA or Hibernate.
  7. Next, expand Annotation Processing in the left side navigation and select Factory Path.
  8. Annotation Processing Screenshot - Factory Path
  9. Here is where you'll point to the jar file containing your metamodel generator. You can see that I unchecked the eclipse version and later tried the Hibernate version and now I'm using the OpenJPA version.
  10. Click OK and you should be good to go.

Also, you'll want to make sure you update your pom.xml to use the same provider.