I have some problems using stored procedures with NHibernate.
CRUD operations are OK but it seems impossible tu use stored procedures to define our own queries.
I work with the last version of NHibernate (NHibernate 1.2.0 beta 2) and with Oracle 10g.
My config file contains:
Code:
...
<property name="dialect">NHibernate.Dialect.OracleDialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
<property name="connection.connection_string">
....
Following the documentation I tried some basic manipulations without succeeding everything.
Getting data from a basic sql call (filling scalar or objects) works but it doesn't work if I just want to fill 2 members of an object (it's the SelectALLSQLPART query).
For each time I tried to call procedure in a query it didn't work.
Is it a known bug for Oracle or my mapping is not correct?
mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="MappingNHibernate" assembly="MappingNHibernate">
<class name="Accounts" table="ACCOUNTS">
<id name="Id" type="Int32" unsaved-value="0">
<column name="ACCOUNTID" sql-type="NUMBER" not-null="true" unique="true" index="IDX_ACCOUNTS"/>
<generator class="sequence">
<param name="sequence">ACCOUNTID_SEQ</param>
</generator>
</id>
<property name="Login" type="String">
<column name="LOGIN" length="128" sql-type="NCHAR" not-null="true" unique="true" index="SYS_C005624"/>
</property>
<property name="Password" type="String">
<column name="PASSWORD" length="128" sql-type="NCHAR" not-null="true"/>
</property>
<property name="Activated" type="String">
<column name="ACTIVATED" length="1" sql-type="CHAR" not-null="true" index="IDX_ACCOUNTS"/>
</property>
</class>
<sql-query name="SelectACCOUNTS">
<return alias="ACCOUNTS" class="MappingNHibernate.Accounts, MappingNHibernate" />
Call ACCOUNTS_P.GetACCOUNTS( ?)
</sql-query>
<sql-query name="SelectALLF">
<return alias="ACCOUNTS" class="MappingNHibernate.Accounts, MappingNHibernate" />
Call ACCOUNTS_P.GetAllAccountsF
</sql-query>
<sql-query name="SelectALLSP">
<return alias="ACCOUNTS" class="MappingNHibernate.Accounts, MappingNHibernate" />
Call ACCOUNTS_P.GetAllAccountsSP()
</sql-query>
<sql-query name="SelectALLSQLFULL">
<return alias="ACCOUNTS" class="MappingNHibernate.Accounts, MappingNHibernate"/>
SELECT * FROM ACCOUNTS
</sql-query>
<sql-query name="SelectALLSQLPART">
<return alias="acc" class="MappingNHibernate.Accounts, MappingNHibernate">
<return-property name="Login" column="myLogin"/>
</return>
SELECT Login myLogin FROM ACCOUNTS
</sql-query>
<sql-query name="SelectALLSQLScalar">
<return-scalar column="ACCOUNTID" type="Int32"/>
<return-scalar column="LOGIN" type="String"/>
SELECT ACCOUNTID, LOGIN FROM ACCOUNTS
</sql-query>
<sql-query name="SelectALLSPScalar">
<return-scalar column="test" type="String"/>
Call ACCOUNTS_P.GetAllAccountsSP()
</sql-query>
</hibernate-mapping>
mapping class:
Code:
using System;
using System.Collections;
using System.Web.UI.WebControls;
namespace MappingNHibernate
{
#region Accounts
/// <summary>
/// Accounts object for NHibernate mapped table 'Accounts'.
/// </summary>
public class Accounts
{
#region Member Variables
protected int _id;
protected string _login;
protected string _password;
protected string _activated;
#endregion
#region Constructors
public Accounts() { }
public Accounts( string login, string password, string activated )
{
this._login = login;
this._password = password;
this._activated = activated;
}
#endregion
#region Public Properties
public virtual int Id
{
get {return _id;}
set {_id = value;}
}
public virtual string Login
{
get { return _login; }
set
{
if ( value != null && value.Length > 128)
throw new ArgumentOutOfRangeException("Invalid value for Login", value, value.ToString());
_login = value;
}
}
public virtual string Password
{
get { return _password; }
set
{
if ( value != null && value.Length > 128)
throw new ArgumentOutOfRangeException("Invalid value for Password", value, value.ToString());
_password = value;
}
}
public virtual string Activated
{
get { return _activated; }
set
{
if ( value != null && value.Length > 1)
throw new ArgumentOutOfRangeException("Invalid value for Activated", value, value.ToString());
_activated = value;
}
}
#endregion
}
#endregion
}
sample test code:
Code:
IQuery q = session.GetNamedQuery("SelectALLSP");
IList accounts = q.List();
Code:
I get these errors when i call procedure and function:
{"ORA-06553: PLS-306: wrong number or types of arguments in call to 'GETALLACCOUNTSSP'"}
and
{"ORA-06576: not a valid function or procedure name"}
I did the test with a sample ADO.NET code and my stored procedure and function work perfectly.
The call made by NHibernate seems to be the problem...
If anyone has information about that...
Thanks
Nicolas