Bytecode enhancement for Hibernate 5.3

I am using this ant target to enhance my bytecode for Hibernate so I can use lazy attribute loading:

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

        <enhance base="${classbin.dir}" dir="${classbin.dir}/org/zfin/publication" failOnError="false" enableLazyInitialization="true"

but it outputed
[enhance] Unable to enhance class: Publication.class

indicating that it is not working. It enhanced other classes in that directory but not this one. Is there any more info why it could not enhance that class? What could be the reason?

It should log out the stack trace that would help you understand why it fails. Maybe you have to enable printing the stack trace somehow?

Good idea. I debugged into it a bit more and stumbled over this line in the byte-buddy (1.8.17)) library’s class ClassVisitor

 public void visitNestHostExperimental(final String nestHost) {
    if (api < Opcodes.ASM7_EXPERIMENTAL) {
      throw new UnsupportedOperationException();
    if (cv != null) {

for some reason the variable ‘api’ is set to a value that it is turned into an UnsupportedOperationException.

So, that method


is called in the ClassReader (of byte-buddy) class when evaluating this variable

String attributeName = readUTF8(currentAttributeOffset, charBuffer)

to the string NestHost.

I figured it out: There is a bug in byte-buddy 1.8.17. Once I upgraded to 1.10.18 the byte code enhancement worked for all my classes!

I wonder if the 5.3.7 release of hibernate should be changed to use the upgraded byte-buddy library.

Well, the latest 5.3 release is 5.3.18 so were clearly using an old version and should update Hiberante in general. The latest version uses bytebuddy 1.9.11