When Hibernate transforms an HQL with joins from an Entity to another entity that inherits from a third entity all of them with filters, the SQL sentence puts a reference from a later join.
If we've got 3 classes: Animal, Dog and Owner. Dog is an Animal and one Dog has only one Owner and viceversa. A Dog has to have an Owner, but we can have an Owner without a Dog.
All querys must be filtered by a company id.
We've got this classes:
This HQL Query:
Is translated to:
The SQL is wrong, in the on clause of dog, it makes a reference to animal, that is joined later. So this query never works.
Hibernate 4.2.6 with MySQL. Hibernate 4.3.8 with HSQLDB.