Hibernate search BytecodeEnhancer issue

Hello,

I have encountered an issue while using Hibernate Search.

The versions I am using are as follows:

  • Java21
  • Spring Boot 3.2.7
  • Hibernate 6.4.9.Final
  • hibernate-search-backend-elasticsearch:7.1.0.Final
  • org.hibernate.search:hibernate-search-mapper-orm:7.1.1.Final
  • VM option: -javaagent:/spring-instrument-6.1.10.jar

Here’s the example code that’s causing the problem:

@Indexed
abstract class Parent {
    @GenericField(projectable = Projectable.YES, sortable = Sortable.YES, searchable = Searchable.YES)
    private LocalDateTime createdDate;
}

class Child extends Parent {

}

When I start the application, I run into this error:

Caused by: java.lang.NoSuchMethodException: com.project.Child.$$_hibernate_read_createdDate()
  at java.base/java.lang.Class.getMethod(Class.java:2395)
  at org.hibernate.search.mapper.orm.model.impl.HibernateOrmBootstrapIntrospector.getBytecodeEnhancerReaderMethod(HibernateOrmBootstrapIntrospector.java:187)
  ... 80 common frames omitted

Upon debugging, I found that the exception is thrown in the following logic, and I suspect a conflict occurs when using the VM option -javaagent:/spring-instrument-6.1.10.jar . If I remove -javaagent:/spring-instrument-6.1.10.jar from the VM options, the method returns null as expected

private static Method getBytecodeEnhancerReaderScheme(Class<?> holderClass, Field field) {
    if (!PersistentAttributeInterceptable.class.isAssignableFrom(holderClass)) {
        return null;
    } else {
        try {
            return holderClass.getMethod("$$_hibernate_read_" + field.getName());
        } catch (NoSuchMethodException e) {
            throw new AssertionFailure("Read method for enhanced field " + field + " is unexpectedly missing.", e);
        }
    }
}

This problem did not occur with earlier versions but has begun after attempting to upgrade. Please, I need a resolution to this issue.

Hello,

Same question asked there: java - Hibernate Search Bytecode Enhancement Issue - Stack Overflow
And reported there: [HSEARCH-5205] - Hibernate JIRA

I’ll answer on the Jira. Locking this.

1 Like