-->
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.  [ 9 posts ] 
Author Message
 Post subject: From Clause Criteria?
PostPosted: Wed Jul 16, 2008 3:52 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
Do you know how to produce this sql with ICriteria? I'm interested in adding extra criteria to the from clause (not in the where clause). Please note this line in the following two queries "this_.SiteProductID <> siteproduc2_.SiteProductID"

I need this:
Code:
select this_.*
from SiteProduct this_

left outer join SiteProduct siteproduc2_
on   this_.ProductID = siteproduc2_.ProductID
and           this_.SiteProductID <> siteproduc2_.SiteProductID
and   siteproduc2_.DeletedOn IS NULL

where this_.DeletedOn is null and this_.SiteID = 119 and this_.IsProduced = 0 and (siteproduc2_.IsProduced = 1 or siteproduc2_.IsProduced is null)


V.S.

I have this:
Code:
select this_.*
from SiteProduct this_

left outer join SiteProduct siteproduc2_
on   this_.ProductID = siteproduc2_.ProductID
and   siteproduc2_.DeletedOn IS NULL

where this_.DeletedOn is null and this_.SiteID = 119 and this_.IsProduced = 0 and (siteproduc2_.IsProduced = 1 or siteproduc2_.IsProduced is null)
and           this_.SiteProductID <> siteproduc2_.SiteProductID


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 3:14 pm 
Newbie

Joined: Sun May 18, 2008 1:21 pm
Posts: 13
First give your mapping information.

2nd mean while try these 3 things

1. create a self join in database
2. in mapping file add a relation to itself.
3. while using ICriteria use Expression.Add(first condition Eq).Add(2nd Condition Eq)

Hope this may help.

_________________
Zafar Ullah

Lead/Architect
www.lmkr.com
www.apextechnologies.ca
Blog
http://barchitect.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 3:16 pm 
Newbie

Joined: Sun May 18, 2008 1:21 pm
Posts: 13
First give your mapping information.

2nd mean while try these 3 things

1. create a self join in database
2. in mapping file add a relation to itself.
3. while using ICriteria use Expression.Add(first condition Eq).Add(2nd Condition Eq)

Hope this may help.

_________________
Zafar Ullah

Lead/Architect
www.lmkr.com
www.apextechnologies.ca
Blog
http://barchitect.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 9:32 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
This is a question about syntax and if this can be accomplished with NHibernate. You can dream up any example to illustrate if it is.

Here is a quote from SQL BooksOnline regarding what I'm trying to accomplish:
Quote:
ON <search_condition>
Specifies the condition on which the join is based. The condition can specify any predicate, although columns and comparison operators are frequently used

There can be predicates that involve only one of the joined tables in the ON clause. Such predicates also can be in the WHERE clause in the query. Although the placement of such predicates does not make a difference for INNER joins, they might cause a different result when OUTER joins are involved. This is because the predicates in the ON clause are applied to the table before the join, whereas the WHERE clause is semantically applied to the result of the join.


It seems that you can only add conditions to the WHERE clause using ICriteria. I need to add it to the ON clause! (see example in original post)

Here is a post with the same issue asked a different way:
http://forum.hibernate.org/viewtopic.php?t=952606&highlight=

Thanks.


Top
 Profile  
 
 Post subject: FROM Clause Criteria?
PostPosted: Mon Sep 15, 2008 11:27 am 
Newbie

Joined: Mon Sep 15, 2008 11:11 am
Posts: 1
Location: Oslo, Norway
Hello gunslinger!

Did you ever get an answer on this? I'm trying to do a very similar thing with HQL, and it would be nice to know if I should just give up or if there is a possible solution out there. I'll switch to the criteria API if necessary.

Sincerely Yours.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 9:01 am 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
Sorry, but I have not. From what I have read (and understood) is that this seems to be a limitation of the ORM. You just have to work around it. :(

Please post back here if you ever come across a solution and I will try to do the same.

Good Luck!


Top
 Profile  
 
 Post subject: any solution
PostPosted: Fri Mar 20, 2009 9:25 am 
Newbie

Joined: Sun May 18, 2008 1:21 pm
Posts: 13
any solution plz????

_________________
Zafar Ullah

Lead/Architect
www.lmkr.com
www.apextechnologies.ca
Blog
http://barchitect.blogspot.com


Top
 Profile  
 
 Post subject: any solution
PostPosted: Fri Mar 20, 2009 9:25 am 
Newbie

Joined: Sun May 18, 2008 1:21 pm
Posts: 13
any solution plz????

_________________
Zafar Ullah

Lead/Architect
www.lmkr.com
www.apextechnologies.ca
Blog
http://barchitect.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 11:26 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
zafarjcp - no solution. :(


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