Metamodel usage with Maven and Intellij


#1

Hello Hibernate enthousiasts !

While trying to setup JPAMetaModelEntityProcessor for my project, I faced some problems.
Following the documentation, the way the metamodel was generated by Maven and Intellij was different.

Intellij was generating it in target/generated-sources/annotations while Maven was generating them in target/generated-sources/apt, I couldn’t find the reason.

One important thing to note in our project is that we are using Mapstruct, which is also generating sources and which does it consistently both via Intellij and Maven. So I had a look how it’s done there and it’s done via the annotationProcessorPaths configuration. So I tried it with hibernate-jpamodelgen and with this configuration (see below), I got a consistent behavior between Intellij and Maven.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven-compiler-plugin.version}</version>
    <configuration>
        <annotationProcessorPaths>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${mapstruct.version}</version>
            </path>
            <path>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-jpamodelgen</artifactId>
                <version>${hibernate.version}</version>
            </path>
        </annotationProcessorPaths>
        <compilerArgs>
            <arg>-parameters</arg>
        </compilerArgs>
    </configuration>
</plugin>

So I wanted to share this with you and have your point of view. Do you think it’s ok ?
Do you think it’s worth updating the documentation ? I would be more than happy to contribute if you could point me where to do it.


#2

IDEA should just use the Maven plugin to generate the metamodel classes.

Sure. Send us a Pull Request if you want to enhance the docs. Just use the documentation folder in hibernate-orm and find the appropriate adoc file in the userguide folder.