Domanda

I am upgrading a project from using java 6 to java 7 and ran into this problem. This project is using spring and JPA 2.0. There are some classes that have a StaticMetaModel annotation. When I compile in java 6 there is no problem, but when I compile in java 7 I see the following error:

...\trunk\target\generated-sources\annotations\..\[SOME_NAME]Entity_.java:[8,16] error: duplicate class: [SOME_NAME]Entity_

Basically java 7 is running some kind of annotation processor that copies over these classes to the generated-sources\annotations folder and then it is trying to compile against this path. This will never work as those classes exist elsewhere and were copied over from that other location to this new location. Obviously this is why I am getting the "duplicate class error", but I am not sure how to fix this.

Java 6 seems to ignore this issue.

Here is the part of my pom file that I think might have to do with it.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

The following was commented out in this plugin, but when added it had no effect that I could recognize.

<compilerArguments>
    <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
È stato utile?

Soluzione

Without fail if I post a question some where I always find the solution right after. Hopefully this will help someone else who might run into this.

Apparently this code is old and for some reason the @StaticMetaModel classes were generated manually and included as part of the project in the src folder path. Maybe this was a bug with java 6 that made it not recognize the sources under ../generated-code/annotations. I had simply to remove the copy in our src folder path and everything works fine.

Maybe someone else with more experience can comment and describe exactly how the annotation processor works in JPA/hibernate, but basically it seems to be checking for classes with @Entity and then creates .java versions of them with the @StaticMetaModel annotation and then puts them in the ../generated-code/annotations folder. If I try to run compile in Intellij it will fail at first, but if I run the compile stage in maven and then I compile in Intellij everything is fine as expected.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top