2

我正在尝试为 Maven 项目中的实体启用 Hibernate 检测。Instrumentation 似乎在只有 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 原型生成的,我正在尝试在 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 找不到它。

4

3 回答 3

1

最新的 Hibernate 4.2.7 SP1 使用 Javassist 3.18.0 最终解决了所讨论的问题。

于 2013-10-24T06:25:28.117 回答
1

这似乎与 javassist-3.15.0 有关。对我们来说,更高的版本已经工作了(3.17.1),但是这个版本严重破坏了代理(https://hibernate.atlassian.net/browse/HHH-7884),所以 Hibernate 团队决定回到 3.15.0 .

所以最后我们在这里遇到了同样的问题......

于 2013-03-21T15:34:24.860 回答
0

我目前的方法是使用 javassist 3.17.1 进行检测并在应用程序 war 文件中部署 javassist 3.15.0。希望这能方便地工作......

更新:到目前为止似乎有效,但这是一个非常丑陋的解决方法......

于 2013-03-22T07:22:24.463 回答