The attached test case works, giving the SQL:
select concrete2x0_.entityId as col_0_0_ from CON2 concrete2x0_ order by concrete2x0_.entityId ASC
select concrete1x0_.entityId as col_0_0_ from CON1 concrete1x0_ order by concrete1x0_.entityId ASC
and a warning: HHH000180: FirstResult/maxResults specified on polymorphic query; applying in memory!
Limits are not specified in the test case, regardless, this can be done in the database as:
(select entityId from CON2
select entityId from CON1)
order by entityId ASC
And even with limits and sort conditions it can be done as:
select * from (
(select * from (select entityId from CON2 order by entityId ASC) where rownum <= 10)
(select * from (select entityId from CON1 order by entityId ASC) where rownum <= 10)
) where rownum <= 10 order by entityId ASC
and also more generally with LIMIT and more sort columns, I believe.
Windows 7 Professional SP1, Oracle 12c, jdk-8u73-windows-x64
Your test case does limit the number of results with: queri.setMaxResults(10). When that line is commented out, the warning is not logged.
More importantly, your named query is on a class that is a mapped superclass.
JPA 2.1, 2.11.2 Mapped Superclasses, says:
"A mapped superclass, unlike an entity, is not queryable and must not be passed as an argument to
EntityManager or Query operations."
Hibernate should throw an exception in this case.
Ah, OK. In that case, how about this as an enhancement, as it seems almost supported already?
The sorting/limiting can be done fully in the database and it fits the concept of mapping object hierarchies to relational tables.
Alternatively, how would I query a hierarchy of objects in Hibernate as, unless I am mistaken, I can't guarantee to query a single concrete type under a mapped superclass unless it has either a supertype or a subtype (HHH-10628)?
Basically I need to be able to either:
Return results from multiple tables with the combined result sorted by a common column (on the abstract supertype) and limited.
Return ordered/limited results for each concrete type in the hierarchy individually.