-->
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.  [ 3 posts ] 
Author Message
 Post subject: NHibernate parses my formula incorrectly
PostPosted: Thu Jun 30, 2005 8:05 am 
Newbie

Joined: Thu Jun 30, 2005 7:44 am
Posts: 1
Location: Amsterdam
We are having problems creating computed properties using the FORMULA attribute of the Property element.

Allow me to set up the scenario; We wish to have a computed property in our class that (obviously) does not map directly to a column in the SQL server table. The Property SIDE is computed from whether the quantity field is positive or negative (for our own reasons it is actually the inverse e.g., -1 for BUY, a Positive amount , and 1 for SELL a negative amount).

We wish to be able to search and return lists based upon this property.
We created a property in our mapping XML file using a formula; We tried many variations but it seems that NHibernate, when it parses the SQL string , wants to qualify all the keywords in the SQL with 'this' unless it is a simple string.

An example:
Code:
<property name="Side" formula="(select convert(smallint, (-1 * sign(O.quantity))) from dbo.tblorders o where o.orderid = this.Orderid)" />

When the application is run , the actual SQL sent to the server ends up as
Code:
(select convert(this.smallint, (-1 * sign(O.quantity))) from dbo.tblorders o where o.orderid = this.Orderid) as f0_11_


Similarly, if I attempt a CASE switch , all the words are qualified :
Code:
select 'OrderSide' = case when o.quantity >= 0 then -1 else 1 end from dbo.tblOrders O where o.orderid = Orderid)
ends up i the captured SQL as
Code:
(select ''OrderSide'' = this.case this.when o.quantity >= 0 this.then -1 this.else 1 this.end from dbo.tblOrders O where o.orderid = this.Orderid) as f0_11_


We have tested the formula attribute for a Property with simpler SQL strings and it does seem to work.

Please help a) Why are some of the strings have all words qualified and others not. b) Is there some way to stop this qualification of tables?

Kind Regards :roll:


Top
 Profile  
 
 Post subject: same problem with formula property
PostPosted: Thu Sep 15, 2005 11:29 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
i have exactly the same problem

Want to do something like
Code:
<property name="Zugeteilt" type="YesNo" update="false" insert="false" formula="(case when PoolId != '' then 'T' else 'F' end)"></property>

this end's up in an SQL-Statement like
Code:
(plansatz0_.case plansatz0_.when plansatz0_.PoolId != '' plansatz0_.then 'T' plansatz0_.else 'F' plansatz0_.end) as f0_

which is of course absolutely senseless...
Did you have any replacements/ideas how to deal with this ??

greetings
Helmut


Top
 Profile  
 
 Post subject: suggestion
PostPosted: Thu Sep 15, 2005 11:37 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
i think it's necessary for nhibernate to do replacements, becouse it
uses table-aliases for it's own at runtime, no one knows while coding.
suggestion:
do only replacements of 'this.' which we use within formulas.
i'm not sure, but i saw a few hibernate samples which makes me think, it was thought to be implemented that way.
any feedback would be nice ;-)

sample-formula:
Code:
(case when this.id != '' then 'T' else 'F' end)

could be replaced with
Code:
(case when <nhib-temp-alias>.id != '' then 'T' else 'F' end)


greetings
Helmut


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