I’ve got a stored procedure in Oracle:
procedure Test(results OUT gencursor, id in number) is
v_cursor gencursor;
begin
OPEN v_cursor FOR
select id, name, age from tblcustomers s where s.id = id;
results:=v_cursor;
end Test;
Now, i’d like to execute this procedure using nHibernate ISession.CreateSQLQuery. All the examples I’ve seen until now use ISession.GetNamedQuery().
So, I’d want to do something like (ToDataTable is my own extension method on IQuery, I have more extension methods which I’d want to stay using in combination with stored procedures):
var result = session
.CreateSQLQuery("call MyPackage.Test(:id)")
.SetDecimal("id", 33)
.ToDataTable();
The code above throw the following exception:
“could not execute query [ call
MyPackage.Test(?) ] Name:id – Value:33
[SQL: call MyPackage.Test(?)]”
I’ve also tried:
var result = session
.CreateSQLQuery("call MyPackage.Test(:result, :id)")
.SetDecimal("id", 33)
.ToDataTable();
That one throw the exception:
Not all named parameters have been
set: [result] [call MyPackage.Test(:result,
:id)]
I don’t now if you can call sps from CreateSQLQuery, but I’ll show you how we call Oracle sps from NHibernate in my current project:
In a mapping file the named query is defined like so:
Works like a charm 🙂