-->
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: Combine UDFs in a criteria.
PostPosted: Sun Mar 23, 2008 3:36 am 
Newbie

Joined: Mon Dec 24, 2007 2:04 am
Posts: 6
Hello everybody,

I would like to use a UDF (an SQL User Defined Function) within a criteria.
I know how to do it with HQL:

"from Customer c where dbo.some_udf(c.id) = [something]"

I don't know how to do it using an ICriteria. I would love to see an example.

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 8:34 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can use a custom sql expression in a criteria, like

Code:
ICriteria crit = session.CreateCriteria( typeof( Customer), "c" );
crit.Add( Expression.Sql( "dbo.some_udf(c.id) = ?", something , NHibernateUtil.Int32 ) );

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Thanks for the reply
PostPosted: Mon Mar 24, 2008 9:16 am 
Newbie

Joined: Mon Dec 24, 2007 2:04 am
Posts: 6
Hi Wolli,

I have tried your code, but it did not work.
It throws an ADO exception and in the generated SQL I see that it uses: "dbo.some_udf(c.id)" even though the alias in the SQL for Customer is not 'c' but 'this_'...
So, the expected syntax is "dbo.some_udf(this_.id)"...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 3:24 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Probably the sql expression is put into the generated sql "as is" without substitution. Try to call the function without the alias.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 4:21 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I just was remembered of how to specifiy the alias there:

Code:
ICriteria crit = session.CreateCriteria( typeof( Customer), "c" );
crit.Add( Expression.Sql( "dbo.some_udf({alias}.id) = ?", something , NHibernateUtil.Int32 ) );

_________________
--Wolfgang


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.