views:

161

answers:

2

Hello all, I can't find what's going on with the following nHibernate HQL.

here's my VB.Net code:

Return _Session.GetNamedQuery("PersonAnthroSummary").SetInt32(0, 2).UniqueResult()

My Named Query:

<sql-query name="PersonAnthroSummary">
           select New PersonAnthroSummary( Anthro.Height, Anthro.Weight ) from PersonAnthroContact as Anthro where Anthro.ID = ? 
  </sql-query>

and i am importing the DTO class:

<import class="xxxxxxx.DataServices.PersonAnthroSummary, xxxxxxx.DataServices"/>

PersonAnthroSummary has a constructor that will take height and weight arguments.

when i test this, nHibernate throwing following exception:

{"Incorrect syntax near 'Anthro'."}

and generated QueryString is:

"select New PersonAnthroSummary( Anthro.Height, Anthro.Weight ) from PersonAnthroContact as Anthro where Anthro.ID = @p0"

Can some one tell me what i'm doing wrong here?.

+1  A: 

You are declaring it as a SQL query instead of a HQL query.

The element name should be <query>.

Diego Mijelshon
I changed it from <sql-query .../> to <query .../>, now i am getting this exception: "Errors in named queries: {PersonAnthroSummary}". thanks for your responce.
Rey
Try *new* instead of *New*
Diego Mijelshon
Hello Diego, i tried new insteadof New, but i am getting same error.. is thr anyway to know actual problem ..insteadof this not friendly message...
Rey
A: 

I figured it out. actual problem with my DTO class PersonAnthroSummary, which has a constructor that takes arguments of type decimal. but PersonAnthroContact mapping, those 2 columns mapped to dirrefent types. i changed PersonAnthroSummary constructor to take those types instead of decimals , then its working....

Rey