Consider the following entities:
Post
Comment (abstract)
->PostComment (extends Comment, models a comment to a post) |
PostComment has a foreign key to Post: PostComment.post => Post.id
Comment has a discriminator column called commentType: discriminator value for PostComment is 'PC'.
Then, consider a join between PostComment and Post: the problem is most evident with a right join:
This should show all the possible tuples (postid-commentid). For posts without comments, I expect to see tuples like (postid-null). However, the produced SQL looks like:
However, this is not the intended behaviour and this will produce as a result only tuples where comment.id is not null. This is because the "where" clause is filtering out all the rows where the CommentTable columns are null, invalidating the use of the right join.
The correct query that should be produced is:
That is, the condition to match the subclass entity should be added to the join conditions, not to the "where" clause, so that they are applied before joining.
|