Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEFT JOIN with JOINED inheritance strategy #2089

Closed
danielyien opened this issue Jan 19, 2017 · 2 comments
Closed

LEFT JOIN with JOINED inheritance strategy #2089

danielyien opened this issue Jan 19, 2017 · 2 comments

Comments

@danielyien
Copy link

danielyien commented Jan 19, 2017

Hello,

I have a class Person and two classes (Employee and Manager) that extends Person. I'm using hibernate JOINED inheritance strategy.
I also have a class Work that has an attribute person of type Person.

I'm having problems with the following query:

QWork work = Qwork.work;
QEmployee employee = QEmployee.employee;
QManager manager = QManager.manager;

getJPAQuery()
	.from(work)
	.leftJoin(work.person, employee)
	.leftJoin(work.person, manager)
	.fetch();

The generated SQL is something like:

SELECT *
FROM
    Work
    LEFT JOIN Person ON Work.personId = Person.personId
    INNER JOIN Employee ON Person.personId = Employee.personId
    INNER JOIN Manager ON Person.personId = Manager.personId

The problem is that my query is getting no results because of the INNER JOIN clauses.
The join between the parent table Person and the child tables (Employee and Manager) should have been done with LEFT JOIN instead of INNER JOIN.

I also tried adding the _super reference but it didn't work:

getJPAQuery()
	.from(work)
	.leftJoin(work.person, employee._super)
	.leftJoin(work.person, manager._super)
	.fetch();

How can I do this kind of query involving LEFT JOIN between parent and child tables?

@johnjaylward
Copy link

Are you trying to just get the work details, or do you want the work details along with the employee and manager details?

@jwgmeligmeyling
Copy link
Member

QueryDSL is not responsible for rendering SQL, your ORM is, probably Hibernate. This appears to be a Hibernate issue. Please validate on a recent Hibernate version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants