| I have a many-to-many bi-directional association between EntityA and EntityB. Also I have a removed boolean flag to soft delete the EntityA when needed. During a left outer join, I was expecting to get only the non removed items from EntityA when fetching the bag from EntityB as I added a @Where annotation there to exclude the removed items (please see attachments). An inner join is working fine. More information below.
- Left Outer Join test
The following JPQL:
It is being turned into the following SQLs:
Additionally, another SQL is executed to load the entity:
The above SQL is retrieving the removed entities which is wrong. I think it's because the double left outer join for both the entity_a_b and and entity_a tables. I think what's happening is that the entityA item is not being fully loaded because of that and then Hibernate is running a second query to hydrate the entityA finally. Is this expected behavior? Why does my @Where end up being ignored in the final result?
- Inner Join test
The following JPQL:
It is being turned into the following SQL:
The above SQL query is not retrieving the removed entities which is right. |