This bug might be related to https://hibernate.atlassian.net/browse/HHH-13712
Whats the issue?*
If you run the http://localhost:8080/subobj, the select query generates fine. But the count query doesn't contain JOIN statement so making the ' where ( subobject0_1_.DELETED = 0)' clause invalid.
Which results in following exception:
How to reproduce:
Clone and run https://github.com/gtiwari333/hibernate-inheritance-JOINED-with-where-bug then open http://localhost:8080/subobj on your browser
It appears the issue is only with InheritanceType.JOINED. Other types works fine (see ``bug.entity.Super.java``)
No issue when hibernate.version = 5.4.4.Final
Related JIRA issue https://hibernate.atlassian.net/browse/HHH-13712?jql=text%20~%20%22Inheritance%20count%20where%22. Looks like its not fixed for JOINED with @Where
AST for both issues
AST for select query
AST for count query
I attached a reproducer. This is in fact an issue with determining the participating tables. I’ll check what I can do about this.
In the meantime you can disable this optimization by setting the property hibernate.query.omit_join_of_superclass_tables to false
Would be awesome if you could check whether the following PR fixes your issue: