JUnit tests fail with Java error when using IntelliJ in maven module after adding Hibernate metamodel classes

In my project, we used the Hibernate Metamodel Generator (JPA) to make the Criteria query safe. This all works fine in our application, however, when we run JUnit tests in this Maven module using our IDE, they now fail with the following error: -

Error:java: Annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' not found

I think it has to do with the fact that in our generated classes: -

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor") @StaticMetamodel(MyEntity.class)

When Maven runs tests as part of our build process, they run without any problems.

I suspect I am missing something in my IDE setup, which is IntelliJ IDEA 14. Any ideas what this might be? Or have I done something wrong in Maven?: -

   <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>2.1.0</version>
            <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>4.3.4.Final</version>
                    <optional>true</optional>
                </dependency>
            </dependencies>
        </plugin>

      

+3


source to share


2 answers


I had a similar problem after upgrading to IntelliJ IDEA 14.1.2 . For me, the following solution solved the problem:

Go to Settings> Build, Execution, Deployment> Compiler> Annotation Processors.



To the left of this config pane I have for every maven module in my project. I have not configured these profiles myself: they may have been deduced . I don't know, but some of these annotation profiles had support for allow annotations enabled . Moreover, in some cases, JPAMetaModelEntityProcessor is explicitly listed here as an annotation processor. After removing the annotation processor from the profile and turning it off, the error went away and my test was successful. Annotation profile

IDE

flag

checkbox

+10


source


@Jeroen Noels answer disables annotation processing in IDEA.

To enable it I added



<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>4.3.4.Final</version>
    <scope>provided</scope>
</dependency>

      

to Maven dependencies i.e. to the classpath. Please note that the scope provided

!

+3


source







All Articles