qwer
qwer

Reputation: 1

Hibernate Search Bytecode Enhancement Issue

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 
VM option: -javaagent:/aspectjweaver-1.9.22.jar -javaagent:/spring-instrument-6.1.10.jar

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

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

@Entity
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.

For your information, it appears that the PersistentAttributeInterceptable interface is being set as reflectionData on the child class entity.

Upvotes: 0

Views: 77

Answers (0)

Related Questions