-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: ICriteria and duplicate association path
PostPosted: Wed Nov 14, 2007 7:39 pm 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
I need to flatten a relational structure. I am performing a projection based upon joined data. I've not included the projection below because it's not relevant to my question.

Using ICriteria I receive a "NHibernate.QueryException: duplicate association path: Parent.Child" exception with the following query:

Code:
ICriteria q = session.CreateCriteria(typeof(Parent), "p")
.CreateCriteria("p.Child", "c1", JoinType.LeftOuterJoin)
.Add(Expression.Eq("c1.Key", 'VALUE_1'))
.CreateCriteria("p.Child", "c2", JoinType.LeftOuterJoin)
.Add(Expression.Eq("c2.Key", 'VALUE_2');



However the equivalent IQuery is valid:

Code:
select from Parent p
left outer join p.Child c1
left outer join p.Child c2
where c1.Key = 'VALUE_1'
and c2.Key = 'VALUE_2'



Have I missed something? Is this a known problem?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 11:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
This is probably more of a shortcoming of HQL rather than a feature. The HQL you gave should not be allowed; however, due to the implementation of the HQL parser, we are not catching all the invalid use cases. There is no concrete plan yet, mainly due to a lack of resources, to port over the H3 abstract-syntax-tree-based parser.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 12:20 pm 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
If I understand correctly you are saying that a bug in HQL is allowing the syntax and that ICriteria is actually correct. I don't know what behavior NHibernate is supposed to allow but what I am trying to do should be allowed.

What's the status of the AST parser port? Do you need help? Obviously the answer is yes - what help do you need?

Actually the HQL doesn't give me the data that I want either. I want to generate the following SQL:

Code:
select  {...}
from    Parent p
        left outer join Child c1
          on p.ID = c1.ParentID
          and c1.Key = 'VALUE_1'
        left outer join Child c2
          on p.ID = c2.ParentID
          and c2.Key = 'VALUE_2'



but this is what NHibernate outputs:

Code:
select  {...}
from    Parent p
        left outer join Child c1
          on p.ID = c1.ParentID
        left outer join Child c2
          on p.ID = c2.ParentID
where   c1.Key = 'VALUE_1'
and     c2.Key = 'VALUE_2'



For now I'm going to fall back to ISQLQuery.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 1:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
You issue is perhaps similar to, if not the same as, this:
http://jira.nhibernate.org/browse/NH-514

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 1:14 pm 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
Yes, this is the same problem. From what I understand it's not worth attempting to fix this until the HQL parser rewrite is complete. Once again I am offering help with the rewrite.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 2:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
I think some effort has been put into it already. I believe translation of the grammar has been done; I can't recall exactly where it is at now. Please post a message on the NHibernate-Development mailing list. Perhaps something can be coordinated to get it going again. Thanks for your interest.

_________________
Karl Chu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.