Hi,
After upgrading from Hibernate 5 to Hibernate 6, a native query that used to work now fails with an invalid column name error.
Entity definitions
Base class:
@Entity
@Table(name = "POINTS")
@Inheritance(strategy = InheritanceType.JOINED)
public class Point {
@Id
private Long id;
@Column(name = "POINT_NAME")
private String name;
@Size(max = 250)
@Column(name = "DESCRIPTION")
private String description;
// more columns...
}
Subclass:
@Entity
@Table(name = "REFERENTIALS")
@PrimaryKeyJoinColumn(name = "REFERENTIAL_ID")
public class Referential extends Point {
@NotNull
@Size(max = 30)
@Column(name = "REFERENTIAL_NAME")
private String referentialName;
}
The query
I have a mechanism that dynamically builds a native SQL query, and it produces:
SELECT points_0.*, 0 as clazz_
FROM points points_0
Which is executed with the entity manager :
entityManager.createNativeQuery("SELECT points_0.*, 0 as clazz_ FROM points points_0", Point.class);
This query worked fine with Hibernate 5.
The problem
After upgrading to Hibernate 6, it now fails with the following error:
DEBUG o.h.e.jdbc.spi.SqlExceptionHelper - Unable to find column position by name: referential_name [n/a]
java.sql.SQLException: ORA-17006: Invalid column name
It looks like Hibernate 6 tries to map subclass columns (referential_name) even though the query only targets the base table (POINTS).
How can I execute a native query that maps only to the base class (Point) in Hibernate 6 without Hibernate trying to include subclass columns?
thank you !