-->
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: How to use named parameters for stored procedures.
PostPosted: Thu Jan 11, 2007 12:55 am 
Newbie

Joined: Mon Nov 20, 2006 1:53 am
Posts: 14
I am trying to call a stored procedure in my database. But rather than using indexes for my parameters I want to use the param name that the stored procedure in the db has. This however doies not work and throws an error saying that "Not all named parameters have been set: []"

Hibernate version:
NHibernate 1.2.0 Beta 2

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Server.Test, Server" table="Table01" lazy="false">
<id name="Key" column="myKey" unsaved-value="null">
<generator class="assigned" />
</id>
<property name="MyValue" column="myName" type="String" length="50"/>
<sql-insert check="none"> exec up_InsertData ?, ?</sql-insert>
<sql-update>exec up_UpdateData ?, ?</sql-update>
<sql-delete check="none" >exec up_DeleteData ?</sql-delete>

</class>

<sql-query name="GetAllData">
<return alias="up_GetData" class="Server.Test, Server" >
<return-property name="Key" column="myKey"/>
<return-property name="MyValue" column="myName"/>
</return>
exec up_GetData
</sql-query>

<sql-query name="GetSomeData">
<return alias="up_GetData" class="Server.Test, Server" >
<return-property name="Key" column="myKey"/>
<return-property name="MyValue" column="myName"/>
</return>
exec up_GetSomeData minKey
</sql-query>

<sql-query name="UpdateSomeData">
<return alias="up_UpdateData" class="Server.Test, Server" />
exec up_UpdateData ?, ?
</sql-query>

<sql-query name="InsertSomeData">
<return alias="up_InsertData" class="Server.Test, Server" />
exec up_InsertData ?, ?
</sql-query>

<sql-query name="DeleteSomeData">
<return alias="up_DeleteData" class="Server.Test, Server" />
exec up_DeleteData ?
</sql-query>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

IList testList = session.GetNamedQuery("GetSomeData")
.SetParameter("minKey", key)
.List();

Full stack trace of any exception that occurs:

An unhandled exception of type 'NHibernate.QueryException' occurred in NHibernate.dll

Additional information: Not all named parameters have been set: []


I would like to use named params instead of indexes so that if the order of the params changes in the stored procedure the code will not need to be changed and recompiled. How do i do this?

Clare Stinton


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 1:21 am 
Newbie

Joined: Mon Nov 20, 2006 1:53 am
Posts: 14
Ok I have figured out how to use named parameters - sort of!

How do I get these parameters to be matched up with the ones in my stored procedure though? NHibernate does not seem to use the parameter order necessarily that is in the stored proc in the database.

When accessing a stored proc through .Net you are able to set parameters by the name that they have in the database itself. We do this rather than just using indexed parameters as it means the order of parameters can be changed around without having to recompile the code.

Is there any way to do this through NHibernate??

Clare Stinton


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.