Polymorphic queries in hibernate 6

Hi, in older versions of hibernate the following query was working

SELECT COUNT(x) FROM my.package.MyEntityAInterface x

And the doc for old versions says

Hibernate queries may name any Java class or interface in the from clause. The query will return instances of all persistent classes that extend that class or implement the interface.

In hibernate 6.1-6.2.3
it gives me the error

java.lang.IllegalArgumentException: org.hibernate.query.sqm.InterpretationException: Error interpreting query [SqmRoot not yet resolved to TableGroup]; this may indicate a semantic (user query) problem or a bug in the parser [SqmRoot not yet resolved to TableGroup]

And I can’t find anything about that in migration guides… But also I can’t find anything like it was before about polymorphic queries in the doc. So want to understand if this is a correct behavior or there will be some patches that will bring back support of interfaces

We have a number of queries relying on interfaces so it will take some effort to update and migrate…

Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(hibernate-test-case-templates/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) that reproduces the issue.

In the meantime, try using count(*) instead.

thanks, created issue

1 Like