NHIbernate Property Formula bug?

357 views
Skip to first unread message

robcar

unread,
Mar 5, 2009, 11:56:24 AM3/5/09
to nhusers
Hello

I'm quite a beginner with NHibernate but I have run into a problem I
can't seem to come any closer to fix. Is this a bug?

I'm trying do make my self a class that looks like the following:

public class Price
{
public virtual int PriceId { get; set; }
public virtual int PerQuantityMultiplier { get; set; }
public virtual int Generation { get; set; }
public virtual DateTime EffectiveDate { get; set; }
}

With the following mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
<class name="Volvo.Purchasing.Pricing.DomainModel.Entities.Price,
Entities" >

<id name="PriceId" column="PriceId" type="System.Int32" unsaved-
value="null">
<generator class="native"/>
</id>

<property name="PerQuantityMultiplier" column="Multiplier" not-
null="false" type="System.Int32" insert="true" update="true"/>
<property name="EffectiveDate" column="EffectiveDate" not-
null="true" type="System.DateTime" insert="true" update="true"/>
<property name="Generation" column="Generation" not-null="true"
type="System.Int32" formula="ROW_NUMBER() OVER (PARTITION BY
AgreementId ORDER BY EffectiveDate DESC) as [Generation])" />

</class>

</hibernate-mapping>

When I fetch a list of this class I get an "Can''t execute query
exception". This is because NHibernate prefixes my Formula query and
doesn't seem to recognize the reserved words PARTITION and OVER.
Is there any way to tell NHibernate not to do this replace of my
custom SQL query?

Very, very greatful for any help in this matter.

KR
Robin Carlander

James Gregory

unread,
Mar 5, 2009, 12:53:08 PM3/5/09
to nhu...@googlegroups.com
I don't know if it's of any relevance, but your formula is either missing an opening bracket, or has an extra closing one; the last bracket is unmatched.

Will Shaver

unread,
Mar 5, 2009, 12:58:07 PM3/5/09
to nhu...@googlegroups.com
And by "bracket" he means )

James Gregory

unread,
Mar 5, 2009, 1:00:10 PM3/5/09
to nhu...@googlegroups.com
That I do, a parenthesis if you please.

On Thu, Mar 5, 2009 at 5:58 PM, Will Shaver <will....@gmail.com> wrote:

And by "bracket" he means )

robcar

unread,
Mar 5, 2009, 1:36:48 PM3/5/09
to nhusers
Thanks guys, my bad!

I did some testing enclosing it in parenthesis and messed up when
posting.
Unfortunately this isn't the problem. NHibernate still doesn't
recognize OVER and PARTITION as reserved words.

I also think I messed up with adding a column alias, so the "correct"
formula (that stil causes an exception) is:

robcar

unread,
Mar 6, 2009, 5:55:06 AM3/6/09
to nhusers
Is there anyway to hook into the executing of the SQL so that I can
alter the SQL before it is executed?

Or anyway to stop NHibernate from being "smart".

The SQL NHibernate tries to execute as a result of the configuration
(with the formula) is this:
SELECT this_.PriceId as PriceId0_0_,
this_.Multiplier as Multiplier0_0_,
this_.EffectiveDate as Effectiv3_0_0_,
(ROW_NUMBER() this_.OVER (this_.PARTITION BY this_.AgreementId ORDER
BY this_.EffectiveDate DESC)) as formula0_0_
FROM Price this_

I just need to change this to:

SELECT this_.PriceId as PriceId0_0_,
this_.Multiplier as Multiplier0_0_,
this_.EffectiveDate as Effectiv3_0_0_,
(ROW_NUMBER() OVER (PARTITION BY this_.AgreementId ORDER BY
this_.EffectiveDate DESC)) as formula0_0_
FROM Price this_

Please anyone?

robcar

unread,
Mar 6, 2009, 6:46:45 PM3/6/09
to nhusers
It seems that this is a confirmed bug
http://jira.nhibernate.org/browse/NH-1617

And it seems it is fixed in the trunk version.

To show myself as the complete newbie I am. How do I go about
downloading the this version and compiling it?

/Robin
> > DESC)- Dölj citerad text -
>
> - Visa citerad text -

Tuna Toksoz

unread,
Mar 7, 2009, 1:38:43 AM3/7/09
to nhu...@googlegroups.com

robcar

unread,
Mar 9, 2009, 4:31:26 AM3/9/09
to nhusers
Thanks, it did! :-)

On 7 Mar, 07:38, Tuna Toksoz <tehl...@gmail.com> wrote:
> This should help
>
> http://nhforge.org/blogs/nhibernate/archive/2008/09/06/prepare-your-s...
>
> Tuna Toksözhttp://tunatoksoz.comhttp://turkiyealt.nethttp://twitter.com/tehlike
> > > - Visa citerad text -- Dölj citerad text -

Remco Ros

unread,
Mar 9, 2009, 6:36:41 AM3/9/09
to nhusers
This issue is also related to http://nhjira.koah.net/browse/NH-1654

The specific dialects need to register their reserved keywords.

1654 fixed this for the TOP keyword in MSSql dialects.



On Mar 7, 12:46 am, robcar <rob...@algonet.se> wrote:
> It seems that this is a confirmed bughttp://jira.nhibernate.org/browse/NH-1617
Reply all
Reply to author
Forward
0 new messages