Wrong sql with filter, joined inheritance and OneToOne relationship

Description

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.

Example:

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.

Environment

Hibernate 4.2.6 with MySQL. Hibernate 4.3.8 with HSQLDB.

Assignee

Unassigned

Reporter

BorjaB

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure