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.  [ 2 posts ] 
Author Message
 Post subject: Problem executing a stored procedure
PostPosted: Wed Aug 13, 2008 10:04 am 
Newbie

Joined: Thu Jul 31, 2008 7:45 am
Posts: 5
Location: Sorunda
Hi
I'm encountering a strange problem when I try to execute a stored procedure in my database.
I'm working against Microsofts NorthWind example database and the stored procedure I'm trying to run is the one named "Ten Most Expensive Products". To be able to handle the result from the sp I have created a view on the database side containing two columns (one for the name of the product and one for the price), I've includede the mapping for the view and my stored procedure below. When I run the code I get the exeception:
"Could not execute query
[ exec [Ten Most Expensive Products] ]
[SQL: exec [Ten Most Expensive Products]]"
And examining the InnerExeception makes me no wiser since it tells me: "TenMostE1_14_0_"
The sp itself runs fine when I run it directly on SQL Server.
Any ideas what I'm doing wrong?

NHibernate version: 1.2.0

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="NorthWindNHibernate.ProductAndPriceEntity, NorthWindNHibernate" table="ProductAndPrice">

<composite-id>
<key-property name="tenMostExpensiveProducts" column="TenMostExpensiveProducts" type="System.String" length="40"></key-property>
<key-property name="unitPrice" column="UnitPrice" type="System.Decimal"></key-property>
</composite-id>

</class>

<sql-query name="Ten_Most_Expensive_Products">
<return alias="tenProducts" class="NorthWindNHibernate.ProductAndPriceEntity, NorthWindNHibernate">
<return-property name="tenMostExpensiveProducts" column="TenMostExpensiveProducts"/>
<return-property name="unitPrice" column="UnitPrice"/>
</return>
exec [Ten Most Expensive Products]
</sql-query>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
try
{
   IList products = session.GetNamedQuery("Ten_Most_Expensive_Products").List();
}
catch (Exception ex)
{
   MessageBox.Show(ex.Message);
}

Full stack trace of any exception that occurs:
A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
A first chance exception of type 'NHibernate.ADOException' occurred in NHibernate.dll

Name and version of the database you are using:
MS SQL Server 2005


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 9:15 am 
Newbie

Joined: Thu Jul 31, 2008 7:45 am
Posts: 5
Location: Sorunda
I've solved the problem. Seems it was related to my use of <composite-id> in the mapping file. I rewrote it and used TenMostExpensiveProducts as id and now it works fine.


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