views:

568

answers:

1

I have the following named SQL query defined:

<sql-query name="ItemSearch">
    <return class="ItemSearchResult">
        <return-property name="Item" column="ItemId" />
        <return-property name="Distance" column="Distance" />
    </return>
    SELECT
        Items.*,
        dbo.DistanceBetween(Latitude, Longitude, :lat, :long) AS Distance
    FROM Items
    WHERE Contains(Name, :keywords)
    ORDER BY Distance ASC
</sql-query>

Whenever I try to run my application, I get the generic error "Errors in named queries: {ItemSearch}". Is there something obviously wrong here?

The ItemSearchResult class is a very simple wrapper class that looks like this:

public class ItemSearchResult
{
    public Item Item {get; set;}
    public double Distance {get; set;}
}
A: 

Here is a sample from my code: The only few things that are different between the NHibernate version and my Hibernate is the auto-import and I would assume the package.

<hibernate-mapping auto-import="true" package="PackageName">
  <class name="Name of class to maptop">
    <composite-id>
      <key-property name="<name of parameter>" type="TYPE"/>
    </composite-id>
    <property name="COLUMNNAME" type="TYPE"/>
  </class>
  <sql-query name="queryName">
        <return alias="dr" class="Name of class to map to"/>
select columnName as {dr.nameofColumn}, 
   from table
 </sql-query>
</hibernate-mapping>

I think the problem that exists in your code is that you did not specifically map out the columns and how they map to your class.

Note: If there are any fields that do not correspond to the NHibernate XML format let me know through the comments. I don't have access to my NHibernate mapping files right now.

monksy