Issue Type: Bug Bug
Affects Versions: 3.6.10
Assignee: Unassigned
Components: query-hql
Created: 30/Oct/12 3:43 AM
Description:

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:

select post.id, comment.id from PostComment as comment right join comment.post as post

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:

select post1_.Id as col_0_0_, postcommen0_.Id as col_1_0_ 
 from CommentTable postcommen0_ right outer join PostTable post1_ on postcommen0_.postId=post1_.Id 
 where postcommen0_.CommentType='NW'

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:

select post1_.Id as col_0_0_, postcommen0_.Id as col_1_0_ 
 from CommentTable postcommen0_ right outer join PostTable post1_ on postcommen0_.postId=post1_.Id, postcommen0_.CommentType='NW'

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.

Project: Hibernate ORM
Priority: Major Major
Reporter: Mauro Molinari
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira