Hibernate.orgCommunity Documentation

Chapter 2. Usage

2.1. Usage from the command line
2.1.1. Usage with Ant
2.1.2. Usage with Maven
2.2. Usage within the IDE
2.2.1. Idea
2.2.2. Eclipse
2.2.3. NetBeans
2.3. Processor specific options

The jar file for the annotation processor can be found in the JBoss Maven repository using Example 2.1, “Maven dependency ”.

Example 2.1. Maven dependency


<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>1.0.0</version>
</dependency>

Alternatively, a full distribution package can be downloaded from SourceForge.

In most cases the annotation processor will automatically run provided the processor jar is added to the classpath and a JDK 6 is used. This happens due to Java's Service Provider contract and the fact the the Hibernate Static Metamodel Generator jar files contains the file javax.annotation.processing.Processor in the META-INF/services directory. The fully qualified name of the processor itself is: org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor.

Note

The use of a Java 6 compiler is a prerequisite.

There are several ways of running the annotation processor as part of a Maven build. Again, it will automatically run if you are using a JDK 6 compiler and the annotation processor jar is on the classpath. In case you have more than one annotation processors on your classpath you can explicitly pass the processor option to the compiler plugin:


The maven-compiler-plugin approach has the disadvantage that the maven compiler plugin does currently not allow to specify multiple compiler arguments (MCOMPILER-62) and that messages from the Messenger API are suppressed (MCOMPILER-66). A better approach is to disable annotation processing for the compiler plugin as seen in Example 2.4, “Maven compiler plugin configuration - indirect execution”.


Once disabled, the maven-annotation-plugin for annotation processing (you will need the following additional maven repositories: maven-annotation-plugin and jfrog) can be used. The configuration can be seen in Example 2.5, “Configuration with maven-annotation-plugin”.


Of course you also want to have annotation processing available in your favorite IDE. The following paragraphs and screenshots show you how to enable the Hibernate Static Metamodel Generator within your IDE.

The Hibernate Static Metamodel Generator accepts a series of custom options which can be passed to the processor in the format -A[property]=[value]. The supported properties are: