我已成功使用hibernate3-maven-plugin与Hibernate-Core和EntityManager 3.6.6-FINAL,hibernate-commons-annotations-3.2.0.Final,hibernate-jpa-2.0-api-1.0.1.Final和最近的hibernate-validator-4.0.0.GA。我是通过这个插件生成DDL的;该项目使用JPA进行持久化;因此,该目标使用了JPA配置并且运行良好。
现在,当我使用相同版本的hibernate-core实现hbm2cfgxml和hbm2java时; hibernate注释3.5.6-FINAL(它使用hibernate-core 3.5.6-FINAL作为我排除的依赖)和hibernate commons注释3.2.0.Final;它给出了IncompatibleClassChangeError。我的插件配置:
<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>
错误:
[错误]无法执行目标 org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2cfgxml(hbm2cfgxml) 在项目dss-domain上:执行目标的hbm2cfgxml org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2cfgxml失败: 执行时遇到API不兼容问题 org.codehaus.mojo:Hibernate3的,Maven的插件:2.2:hbm2cfgxml: java.lang.IncompatibleClassChangeError:找到的接口 org.hibernate.cfg.Mappings,但是期望类
任何想法谁是罪魁祸首?新的hibernate版本或插件(可能需要更新,因为它似乎在2.2上很长一段时间。
答案 0 :(得分:2)
我猜这个问题是Hibernate Tools。我认为目前的稳定版本(3.2.4.GA)与Hibernate Core 3.3.X兼容,目前的git master(https://github.com/hibernate/hibernate-tools)与Hibernate Core 3.5.X兼容。您可以尝试安装其中一个github Hibernate Tools forks并在hibernate3-maven-plugin中声明对它的依赖。
https://github.com/axiomalaska/hibernate-tools/tree/3.6.X - Hibernate 3.6.X(披露:我的前叉)
https://github.com/dgeraskov/hibernate-tools/tree/hibernate4 - Hibernate 4.X