I want to write following SQL query:
SELECT * FROM parent
LEFT OUTER JOIN child1 ON parent.ID = child1.PARENT_ID
LEFT OUTER JOIN child2 ON parent.ID = child2.PARENT_ID
LEFT OUTER JOIN grandchild ON child1.GRANDCHILD_ID = grandchild.ID OR child2.GRANDCHILD_ID = grandchild.ID
with JPA CriteriaBuilder.
The SQL table structure looks like this: I have four tables. A parent, two children of it, and a grandchild whose parent can be either children. Something like this:
parent:
- ID
- NAME
child1:
- ID
- NAME
- PARENT_ID
- GRANDCHILD_ID
child2:
- ID
- NAME
- PARENT_ID
- GRANDCHILD_ID
grandchild:
- ID
- NAME
My question is really similar to this one: CriteriaBuilder join two tables with a custom condition Only difference is, that I need to use "JOIN OR" instead of "JOIN AND"