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: Calling Stored Procedures with NHibernate v1.2.0
PostPosted: Thu Jun 28, 2007 5:57 am 
Newbie

Joined: Thu Jun 28, 2007 5:46 am
Posts: 1
For those of you who are having trouble locating an example of how to actually execute a stored procedure with NHibernate, please see the below code that I use to execute mine.

*** MAPPING FILE ***
<sql-query name="MyStoredProcedure">
<return alias="MyObject" class="My.Namespace.MyObject, My.Namespace">
<return-property name="Id" column="ID"/>
<return-property name="Username" column="USERNAME"/>
</return>
exec MyStoredProcedure :PrimaryKey, :Username
</sql-query>

*** EXECUTION CODE (c#) ***
ISession session = base.NHibernateSession;
IQuery query = (IQuery)session.GetNamedQuery("MyStoredProcedure");
query.SetParameter("PrimaryKey", theValue);
query.SetParameter("Username", theValue);
return (MyObject)query.UniqueResult();

Hope this helps. I spent many hours trying all different combinations until this finally worked.


Top
 Profile  
 
 Post subject: Calling Stored Procedures.
PostPosted: Thu Jul 05, 2007 9:29 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
Hi Chris,

Well done. I also took a while to figure that one out. I am still having trouble though. I get some wried errors when trying to run the stored proc.

Message = "could not execute query\r\n[ exec sproc_GetStrategyById ? ]\r\n Name: SgyId - Value: 14\r\n[SQL: exec sproc_GetStrategyById ?]"

This is what the inner exception says.

[System.IndexOutOfRangeException] = {"sgy2_1_0_"}

It gives very little information as to the exact nature of the failure.

Any chance you could post the sample Stored Proc. Did you see any error like this at all. I thought it was a mapping issue but I am pretty sure all the mapping is ok.


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.