Revert HHH-12670 - Allows native SQL queries that take a given resultClass to map the result set to the required type

Description

None

Environment

None

Activity

Show:
Guenther Demetz
July 30, 2018, 2:04 PM

The reverting of causes problems to us for migrating from version 5.3.2 to version 5.3.3.
The problem is that we use interface types when doing queries:

NativeQuery<Company> sqlQuery = session.createNativeQuery("select {c.*} from Company", Company.class);
sqlQuery.addEntity("c", CompanyPeer.class);
List<Company> list = sqlQuery.list();

where _Company _is an interface and _CompanyPeer _is the mapped entity class implementing _Company _interface.
With 5.3.3 this raises org.hibernate.MappingException: Unknown entity: com.wuerth.phoenix.Cis.models.ImplementedCompany
at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:670)
at org.hibernate.engine.spi.SessionFactoryImplementor.getEntityPersister(SessionFactoryImplementor.java:338)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:445)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:498)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:465)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:180)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:74)
at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:41)
at org.hibernate.engine.query.spi.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:213)
at org.hibernate.internal.AbstractSharedSessionContract.getNativeQueryPlan(AbstractSharedSessionContract.java:599)
at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1053)

The problem is, that in AbstractSharedSessionContract the filter has been removed.
this.getFactory().getMetamodel().getEntities()
.stream()
.anyMatch( entityType -> entityType.getJavaType().isAssignableFrom( resultClass ) )

so the return-type get assigned although the type is not assigneable from resultClass ;-(

Guillaume Smet
July 30, 2018, 3:19 PM

This feature introduced regressions, that's why it was reverted.

We agree that what you're trying to do did not work before HHH-12670?

Assignee

Guillaume Smet

Reporter

Guillaume Smet

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure