Unknown entity MappingException when using interfaces as return type

Description

Since years we use interface types as return type when doing queries:

where CompanyPeer is the mapped class which implements Company,
an interface which declares all getter- and setter-methods for the persistent fields.

Now with 5.3.3 the query above raises a MappingException:
org.hibernate.MappingException: Unknown entity: com.zigzag.models.Company
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 with a vital filter has been removed in AbstractSharedSessionContract on line 938, so the return-type get assigned although the type is not assigneable from resultClass

The removed filter is:
this.getFactory().getMetamodel().getEntities()
.stream()
.anyMatch( entityType -> entityType.getJavaType().isAssignableFrom( resultClass ) )

The fix is trivial, just reput the filter as follows on line 938:

If needed, I will provide a test-case tomorrow.

Environment

None

Assignee

Guillaume Smet

Reporter

Guenther Demetz

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Feedback Requested

2018/07/30

Worked in

5.3.2

Feedback Requested By

Guillaume Smet

Components

Affects versions

Priority

Major
Configure