-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems with query using multiple aliases (Parents)
PostPosted: Fri May 11, 2007 12:06 am 
Newbie

Joined: Sat Jun 11, 2005 1:56 am
Posts: 19
Hibernate version:
1.2.0.3001

Name and version of the database you are using:
SQL 2005

Hi All,

This is a bit hard to explain but I'll give it my best.

I have an database schema like this:

ParentEntity1 Parent Entity2
| |
|- Child1 -|

Now either one parent is set on the child at a time. So either:

child1.ParentEntity1 is not null or
child1.ParentEntity2 is not null

Now I'm trying to do a query using ICriteria. The actual query (from hibernate logs) is:

...
WHERE (alias1x2_.[Name] is not null and lower(alias1x2_.[Name]) like ? escape '\')
or (alias2x3_.[Name] is not null and lower(alias2x3_.[Name]) like ? escape '\')

This returns 0 rows. However I know that the first part of that query should return 1 row.

Do I have to add a check to see if the alias is null? something like:
WHERE (alias1x2_ is not null and alias1x2_.[Name] is not null and lower(alias1x2_.[Name]) like ? escape '\')
or (alias2x3_ is not null and alias2x3_.[Name] is not null and lower(alias2x3_.[Name]) like ? escape '\')


Thanks in advanced

Guido Tapia


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 7:11 pm 
Newbie

Joined: Sat Jun 11, 2005 1:56 am
Posts: 19
After a bit more investigation, it seems that as soon as I add an alias for a parent entity then it restricts results to rows where that parent is not null. so:

ISession s = ....
ICriteria c = s.CreateCriteria(typeof(ChildEntity));
c.CreateAlias("Parent1", "alias1");
c.CreateAlias("Parent2", "alias2");
// Just by doing this I have restricted results to rows with Parent1 != null and Parent2 != null.

I'm still going through the documentation to see where this is explained.

Any pointers anyone?

Cheers,

Guido Tapia


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