首页 > 解决方案 > Hibernate 5.3.7 的字节码增强

问题描述

我曾经在 Hibernate 4.x 中使用 ant 目标来检测我的类:

<target name="instrument" depends="compile">
        <taskdef name="enhance" classname="org.hibernate.tool.enhance.EnhancementTask">
            <classpath refid="extended.classpath"/>
            <classpath path="${classbin.dir}"/>
        </taskdef>

        <instrument verbose="true">
            <fileset dir="${TARGETROOT}/home/WEB-INF/classes">
                <include name="org/zfin/publication/Publication.class"/>
            </fileset>
        </instrument>
    </target>

但是当我升级到 Hibernate 5.3.7 时,这停止了工作。在蚂蚁中执行此操作的正确方法是什么?注意,我不使用 Maven。

我试过这个改变

    <target name="instrument" depends="compile">
        <taskdef name="enhance" classname="org.hibernate.tool.enhance.EnhancementTask">
            <classpath refid="extended.classpath"/>
            <classpath path="${classbin.dir}"/>
        </taskdef>

        <enhance base="${classbin.dir}" dir="${classbin.dir}/org/zfin/publication" failOnError="false" enableLazyInitialization="true"
                 enableDirtyTracking="false"
                 enableAssociationManagement="false"
                 enableExtendedEnhancement="false">
        </enhance>
    </target>

但它输出 [enhance] Unable to enhance class: Publication.class

表示它不工作。它增强了该目录中的一些类,但不是我需要的。

标签: javahibernatebyte-code-enhancement

解决方案


我发现 Hibernate 5.3.7 正在使用 byte-buddy 1.8.17。升级到 byte buddy 1.10.18 时,一切正常!


推荐阅读