I have an old application which uses entity manager with native queries. The entities are annotated with @SqlResultSetMapping and it uses @ConstructorResult. The application was working fine with older version of Hibernate. However, after the update to hibernate 6.2. The application is no longer able to map field.
For example, let's assume I have a native query "SELECT FIRST_NAME from PERSON"
And assuming I have an entity
@SqlResultSetMapping(
name = "MAPPING_PERSON",
classes = {
@ConstructorResult(
targetClass = PersonPOJO.class,
columns = {
@ColumnResult(name = "FIRST_NAME")
}
)
}
)
@Entity
@Getter
@Setter
public class Person {
private Long id;
private String firstname;
}
And assuming I have a class called PersonPOJO
public class PersonPOJO {
private String firstname;
public Person(String firstname) {
this.firstname = firstname;
}
public String getFirstname() {
return this.firstname;
}
public String setFirstname(String firstname) {
this.firstname = firstname;
}
}
When I use entityManager.createNativeQuery(sqlQuery, "MAPPING_PERSON"), I get an hibernate instantiation exception, Cannot set field "FIRST_NAME" to instantiate.
I tried to debug and I found out that hibernate is using DynamicInstantiationAssemblerInjectionImpl internally, and that class uses findField method of Class.java