问题
I have successfully used hibernate3-maven-plugin with Hibernate-Core and EntityManager 3.6.6-FINAL, hibernate-commons-annotations-3.2.0.Final, hibernate-jpa-2.0-api-1.0.1.Final and hibernate-validator-4.0.0.GA in recent past. I was generating the DDL through this plugin; the project used JPA for persistence; hence that goal used JPA Configuration and worked well.
Now, when I implement hbm2cfgxml and hbm2java using the same version of hibernate-core; hibernate annotation 3.5.6-FINAL (it uses hibernate-core 3.5.6-FINAL as dependency which I excluded) and hibernate commons annotations 3.2.0.Final; it gives IncompatibleClassChangeError. My plugin configuration:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hbm2cfgxml</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2cfgxml</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2cfgxml</name>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<componentProperties>
<ejb3>true</ejb3>
<packagename>foo.bar</packagename>
</componentProperties>
</configuration>
</execution>
<execution>
<id>hbm2java</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
<componentProperties>
<ejb3>true</ejb3>
<packagename>foo.bar</packagename>
<configurationfile>target/hibernate3/generated-mappings/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.16</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.6.6.Final</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
<type>jar</type>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
And the Error:
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2cfgxml (hbm2cfgxml) on project dss-domain: Execution hbm2cfgxml of goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2cfgxml failed: An API incompatibility was encountered while executing org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2cfgxml: java.lang.IncompatibleClassChangeError: Found interface org.hibernate.cfg.Mappings, but class was expected
Any ideas who's the culprit? the new hibernate versions or plugin (which might require update as it seems to be on 2.2 for quite sometime.
回答1:
I'm guessing that the problem is Hibernate Tools. I think the current stable version (3.2.4.GA) is compatible with Hibernate Core 3.3.X and the current git master (https://github.com/hibernate/hibernate-tools) works with Hibernate Core 3.5.X. You might try installing one of these github Hibernate Tools forks and declaring a dependency on it in hibernate3-maven-plugin.
https://github.com/axiomalaska/hibernate-tools/tree/3.6.X - Hibernate 3.6.X (disclosure: my fork)
https://github.com/dgeraskov/hibernate-tools/tree/hibernate4 - Hibernate 4.X
来源:https://stackoverflow.com/questions/7498385/hibernate3-maven-plugin-breaks-with-updated-hibernate-version-3-6-6-final-in