我正在尝试为 Maven 项目中的实体启用 Hibernate 检测。检测似乎在仅具有由 Java API(String、BigDecimal 等)定义的标准类型字段的实体上正常工作,但是当检测任务尝试在具有由我的项目中其他类定义的类型字段的类时,它失败并出现以下错误:
[instrument] processing class : com.test.entity.EntityWithCustomTypes; file = C:\Project\Project-ejb\target\classes\com\test\entity\EntityWithCustomTypes.class
Mar 21, 2013 10:00:24 AM org.hibernate.bytecode.internal.javassist.JavassistClassTransformer doTransform
ERROR: HHH000373: Unable to transform class: cannot find com.test.bo.CustomType
我尝试故意检测 CustomType 类(这不是必需的);仪器对其进行了处理,但在 EntityWithCustomTypes 上仍然出错。
这是我在 pom.xml 中使用的插件;该项目是使用 JBoss 7 Java EE 原型(prototype)生成的,我正在尝试在 EJB 模块 POM 中执行检测:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<configuration>
<tasks>
<taskdef name="instrument" classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
<classpath>
<path refid="maven.dependency.classpath" />
<path refid="maven.compile.classpath" />
<path refid="maven.runtime.classpath" />
<path refid="maven.plugin.classpath" />
<dirset dir="${project.build.outputDirectory}" />
</classpath>
</taskdef>
<instrument verbose="false">
<fileset dir="${project.build.outputDirectory}">
<include name="**/entity/*.class" />
</fileset>
</instrument>
</tasks>
</configuration>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.10.Final</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
</dependencies>
</plugin>
我可以验证编译阶段正在生成相关类(CustomType),因此我无法理解为什么 Hibernate 的 JavassistClassTransformer 无法找到它。
最佳答案
这似乎与javassist-3.15.0有关。对于我们来说,更高的版本已经可以工作(3.17.1),但是这个版本严重破坏了代理( https://hibernate.atlassian.net/browse/HHH-7884 ),因此 Hibernate 团队决定回到 3.15.0。
所以最终我们遇到了同样的问题......
关于Hibernate检测转换失败: cannot find class (HHH000373),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15550061/