[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4991) ManyToMany table not joined due to max_join_depth parameter, results to SQL exceptions

Shawn Clowater (JIRA) noreply at atlassian.com
Tue Apr 6 15:06:02 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4991?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36183#action_36183 ] 

Shawn Clowater commented on HHH-4991:
-------------------------------------

It looks like the getJoinType was overloaded in HHH-3414.  

I'm doing a comparison between 3.3.2 and 3.5.0 on the same test code locally and it looks like Strong is barking up the right tree.

In 3.2.6, the getJoinType that is called by the manyToMany processing is overridden by the CriteriaJoinWalker and gets called by both the walkEntityAssociationTree and then also subsequently by the walkCollectionTree that gets called from the addAssociationToJoinTreeIfNecessary from within the walkEntityAssociationTree.

In 3.5.0, the getJoinType was overloaded and in the case of the manyToMany processing, when it processes the path at from the entity view it calls the getJoinType method that consumes the OuterJoinLoadable persister which is overridden by the CriteriaJoinWalker and it finds the correct join type to use.

However, once it calls addAssociationToJoinTreeIfNecessary it ultimately ends up calling back into the getJoinType method that doesn't consume the OuterJoinLoadable persister.  In this case it ends up failing the isTooDeep check and returns -1 on the join type bypassing the join.

> ManyToMany table not joined due to max_join_depth parameter, results to SQL exceptions
> --------------------------------------------------------------------------------------
>
>                 Key: HHH-4991
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4991
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: query-criteria
>    Affects Versions: 3.5.0-CR-2
>         Environment: Hibernate 3.5.0-CR-2, MacOS X, MySQL 5.1
>            Reporter: Sergii Novotarskyi
>            Assignee: Steve Ebersole
>         Attachments: Example.zip, hhh-4991-testcase.patch
>
>
> *max_join_depth* parameter prevents Hibernate from joining one end of ManyToMany relationship when using Criteria API, if the relationship is "far" enough from the root entity.
> {quote}
>             Criteria c = session.createCriteria(SubEntity.class)
>             					.createAlias("entity", "e") // ManyToOne, inner join
>             					.createAlias("e.entity", "ee") // ManyToOne, inner join
>             					.createAlias("ee.sides", "s") // ManyToMany, inner join + left outer join
>             					.setProjection(Projections.count("id"))
>             					.add(Restrictions.ne("s.data", "abc"));
> {quote}
> When *max_join_depth* is set to *2* (default) the above example generates following SQL query
> {quote}
>     select count(this_.sub_id) as y0_ from SubEntity this_ 
>     inner join SubMainEntity e1_ on this_.submain_id=e1_.submain_id 
>     inner join MainEntity ee2_ on e1_.main_id=ee2_.main_id 
>     inner join MainSide sides7_ on ee2_.main_id=sides7_.main_id 
>     where s3_.data<>?
> {quote}
> The query, naturally, throws the "Unknown column 's3_.data' in 'where clause'" exception.
> Expected query would be
> {quote}
>    select count(this_.sub_id) as y0_ from SubEntity this_ 
>     inner join SubMainEntity e1_ on this_.submain_id=e1_.submain_id 
>     inner join MainEntity ee2_ on e1_.main_id=ee2_.main_id 
>     inner join MainSide sides7_ on ee2_.main_id=sides7_.main_id 
>     left outer join SideEntity s3_ on sides7_.side_id=s3_.side_id 
>     where s3_.data<>?
> {quote}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list