-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Bug now in NHibernate?
PostPosted: Mon Feb 19, 2007 5:25 am 
Newbie

Joined: Mon Feb 19, 2007 5:10 am
Posts: 15
I'm currently using NHibernate-1.2.0.Beta3-debug and have been trying to get subqueries to work. I came across a patch for a bug in Hibernate (Java) which describes exactly the problem I'm seeing in NHibernate: Joins in subqueries using DetachedCriteria do not work.

The Subquery
I can create a subquery and run it independently of the main query:

Code:
DetachedCriteria matchedPostcode = DetachedCriteria.For(typeof(Address), "addr");
matchedPostcode.Add(Expression.InsensitiveLike("addr.Postcode", filter.Postcode, MatchMode.Anywhere));
matchedPostcode.CreateAlias("addr.OrganisationAddressList", "organisationAddress");
matchedPostcode.CreateAlias("organisationAddress.Organisation", "org");               
matchedPostcode.SetProjection(Projections.Property("org.Id"));

ICriteria c = matchedPostcode.GetExecutableCriteria(session);
c.List();

This generates the correct SQL:

Code:
SELECT
org2_.id as y0_
FROM qmis.Address this_
inner join qmis.OrganisationAddress organisati1_ on this_.id=organisati1_.addressId
inner join qmis.Organisation org2_ on organisati1_.organisationId=org2_.id
WHERE lower(this_.postcode) like @p0;
@p0 = '%gl50%'


The Parent Query
However, when I include the subquery in the parent query...

Code:
ICriteria query = session.CreateCriteria(typeof(Organisation));
query.Add(Subqueries.Eq("Id", matchedPostcode));
IList result = query.List();

...the SQL that it generates no longer includes the join conditions of the subquery:

Code:
SELECT
...
FROM qmis.Organisation this_
inner join qmis.OrganisationAddress organisati1_ on this_.id=organisati1_.organisationId
inner join qmis.Address addr2_ on organisati1_.addressId=addr2_.id
WHERE @p0 = (SELECT org2_.id as y0_ FROM qmis.Address this0__ WHERE lower(this0__.postcode) like @p1);
@p0 = 'Id', @p1 = '%gl50%'


Bug?
Can anyone confirm if this is the same bug that Hibernate had? If so, I'll create a JIRA case.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 6:12 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Since the source is the same, I guess the bug is there too. Report it please.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 7:30 am 
Newbie

Joined: Mon Feb 19, 2007 5:10 am
Posts: 15
Case raised: NH-911


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 5:23 am 
Newbie

Joined: Mon Feb 19, 2007 5:10 am
Posts: 15
Thanks for the rapid response and sorting out of this case. This is the first time I've submitted a bug for a project like this and I've been very impressed as to how easy and smooth it has been.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 5:37 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Well, it wasn't patched yet, I just assigned it to be fixed in the next version, this may change though.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.