# Bytecode enhancement for Hibernate 5.3

**URL:** <https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754>\
**Category:** Hibernate ORM\
**Created:** [November 9, 2020, 4:51pm UTC](https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754 "2020-11-09T16:51:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmpich](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cmpich](https://discourse.hibernate.org/u/cmpich)\
**Post date:** [November 9, 2020, 4:51pm UTC](https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754/1 "2020-11-09T16:51:53Z")

</div>

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

```auto
<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>

```

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?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 10, 2020, 3:16pm UTC](https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754/2 "2020-11-10T15:16:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cmpich](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cmpich](https://discourse.hibernate.org/u/cmpich)\
**Post date:** [November 10, 2020, 3:53pm UTC](https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754/3 "2020-11-10T15:53:37Z")

</div>

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

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

```

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

---

<div class="post-metadata">

**Author:** ![cmpich](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cmpich](https://discourse.hibernate.org/u/cmpich)\
**Post date:** [November 10, 2020, 4:11pm UTC](https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754/4 "2020-11-10T16:11:29Z")

</div>

So, that method

```auto
visitNestHostExperimental()

```

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

```auto
String attributeName = readUTF8(currentAttributeOffset, charBuffer)

```

to the string `NestHost`.

---

<div class="post-metadata">

**Author:** ![cmpich](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cmpich](https://discourse.hibernate.org/u/cmpich)\
**Post date:** [November 10, 2020, 7:27pm UTC](https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754/5 "2020-11-10T19:27:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 10, 2020, 8:58pm UTC](https://discourse.hibernate.org/t/bytecode-enhancement-for-hibernate-5-3/4754/6 "2020-11-10T20:58:19Z")

</div>

Well, the latest 5.3 release is [5.3.18](https://github.com/hibernate/hibernate-orm/releases/tag/5.3.18) so were clearly using an old version and should update Hiberante in general. The latest version uses bytebuddy 1.9.11
