jpa-metamodels-with-maven


Sourcecode

$ git clone git@github.com:jinahya/jpa-metamodels-with-maven.git
$ cd jpa-metamodels-with-maven
$ git checkout develop
$ mvn help:all-profiles

Hibernate

With direct dependencies

<dependencies>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <scope>compile</scope>
    <optional>true</optional>
  </dependency>
</dependencies>

Using maven-processor-plugin

<build>
  <plugins>
    <plugin>
      <groupId>org.bsc.maven</groupId>
      <artifactId>maven-processor-plugin</artifactId>
      <executions>
        <execution>
          <id>process</id>
          <goals>
            <goal>process</goal>
          </goals>
          <phase>generate-sources</phase>
          <configuration>
            <processors>
               <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
            </processors>
          </configuration>
        </execution>
      </executions>
      <dependencies>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-jpamodelgen</artifactId>
          <version>${hibernate.version}</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>

Apache OpenJPA

With direct dependencies

It seems that Apache OpenJPA must be triggered with a specific compiler argument.

<dependencies>
  <dependency>
    <groupId>org.apache.openjpa</groupId>
    <artifactId>openjpa</artifactId>
    <scope>compile</scope>
    <optional>true</optional>
  </dependency>
</dependencies>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <compilerArgs>
          <arg>-Aopenjpa.metamodel=true</arg>
        </compilerArgs>
      </configuration>
    </plugin>
  </plugins>
</build>

Using maven-processor-plugin

Again, Apache OpenJPA requires some additional configuration.

<build>
  <plugins>
    <plugin>
      <groupId>org.bsc.maven</groupId>
      <artifactId>maven-processor-plugin</artifactId>
      <executions>
        <execution>
          <id>process</id>
          <goals>
            <goal>process</goal>
          </goals>
          <phase>generate-sources</phase>
          <configuration>
            <processors>
              <processor>org.apache.openjpa.persistence.meta.AnnotationProcessor6</processor>
            </processors>
            <optionMap>
              <openjpa.metamodel>true</openjpa.metamodel>
            </optionMap>
          </configuration>
        </execution>
      </executions>
      <dependencies>
        <dependency>
          <groupId>org.apache.openjpa</groupId>
          <artifactId>openjpa</artifactId>
          <version>${openjpa.version}</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>

EclipseLink

For EclipseLink, the location of persistence.xml must be specified.

Using direct dependencies

<dependencies>
  <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
    <scope>compile</scope>
    <optional>true</optional>
  </dependency>
</dependencies>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <compilerArgs>
          <arg>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</arg>
        </compilerArgs>
      </configuration>
    </plugin>
  </plugins>
</build>

Using maven-processor-plugin

<build>
  <plugins>
    <plugin>
      <groupId>org.bsc.maven</groupId>
      <artifactId>maven-processor-plugin</artifactId>
      <executions>
        <execution>
          <id>process</id>
          <goals>
            <goal>process</goal>
          </goals>
          <phase>generate-sources</phase>
          <configuration>
            <processors>
              <processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>
            </processors>
            <compilerArguments>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</compilerArguments>
          </configuration>
        </execution>
      </executions>
      <dependencies>
        <dependency>
          <groupId>org.eclipse.persistence</groupId>
          <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
          <version>${eclipselink.version}</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>

DataNucleus

Using direct dependencies

When working with DataNucleus, an additional dependency needs to be specified.

<dependencies>
  <dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-jpa-query</artifactId>
    <scope>compile</scope>
    <optional>true</optional>
  </dependency>
  <dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>${datanucleus.version}</version>
    <scope>compile</scope>
    <optional>true</optional>
  </dependency>
</dependencies>

Using maven-processor-plugin

<build>
  <plugins>
    <plugin>
      <groupId>org.bsc.maven</groupId>
      <artifactId>maven-processor-plugin</artifactId>
      <executions>
        <execution>
          <id>process</id>
          <goals>
            <goal>process</goal>
          </goals>
          <phase>generate-sources</phase>
          <configuration>
            <processors>
              <processor>org.datanucleus.jpa.query.JPACriteriaProcessor</processor>
            </processors>
          </configuration>
        </execution>
      </executions>
      <dependencies>
        <dependency>
          <groupId>org.datanucleus</groupId>
          <artifactId>datanucleus-jpa-query</artifactId>
          <version>${datanucleus.version}</version>
        </dependency>
        <dependency>
          <groupId>org.datanucleus</groupId>
          <artifactId>datanucleus-core</artifactId>
          <version>${datanucleus.version}</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>
About these ads

One comment

  1. Pierre Caron

    Thank you very much! I am new to Maven and now my metamodels classes get generated! Thanks for indicating that the location of persistence.xml must be specified.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s