我也无法通过 ref_cursor 从存储过程中获取数据。也许您可以建议您如何解决该问题-
我的错误:“ORA-06553:PLS-306:调用'GET_SAMPLE_LIST'时参数的数量或类型错误”}我想调用中的参数类型是问题
这是我的代码:
HBM
<?xml version="1.0" encoding="utf-8" ?>
<!-- Generated by MoreGen 28-Apr-2008 11:27:28 -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Infra"
namespace="Infra.Entities">
<class name="Sample" table="MY_PACK.Get_Sample_List" lazy="true">
<id name="Id" column="ID">
<generator class="native" />
</id>
<property name="Makat8" column="makat8" />
<property name="SerialNumber" column="serial_number" />
<loader query-ref="MY_PACK.Get_Sample_List"/>
</class>
<sql-query name="MY_PACK.Get_Sample_List" callable="true" >
<query-param name="p_crs" type="OracleDbType.RefCursor" />
<query-param name="p_1" type="int" />
<query-param name="p_2" type="string" />
<query-param name="p_3" type="int" />
<query-param name="p_4" type="date" />
<query-param name="p_5" type="date" />
<return alias="MY_PACK.Get_Sample_List" class="Sample">
<return-property name="Makat8" column="makat8" />
<return-property name="SerialNumber" column="serial_number" />
</return>
call MY_PACK.Get_Sample_List (:p_crs, :p_1 , :p_2 , :p_3 , :p_4 , :p_5)
</sql-query>
</hibernate-mapping>
SAmple 实体:
public class Sample
{
public virtual int Id { get; set; }
public virtual int Makat8 { get; set; }
public virtual int SerialNumber { get; set; }
}
会话配置 - 它很流畅,但仍然相同:
m_Factory = Fluently.Configure() //cfgRules
.Database(OracleClientConfiguration.Oracle10.Dialect("NHibernate.Dialect.Oracle10gDialect")
.ConnectionString(x => x.FromConnectionStringWithKey("MyDBCONNSTRING"))
.Driver<NHibernate.Driver.OracleDataClientDriver>().ShowSql())
.ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none"))
.Mappings(m =>
{
m.FluentMappings.AddFromAssemblyOf<MyEntityMapping>();
m.HbmMappings.AddFromAssemblyOf<MyHBMMapping>();
m.MergeMappings();
})
.BuildConfiguration()
.BuildSessionFactory();
有测试:
using (ISession Session = NHibernateSessionProvider.GetSession("MyDBCONNSTRING"))
{
using (NHibernate.ITransaction Tran = Session.BeginTransaction(System.Data.IsolationLevel.Serializable))
{
IQuery query = (IQuery)Session.GetNamedQuery("MY_PACK.Get_Sample_List").SetResultTransformer(Transformers.AliasToBean(typeof(Sample))); ;
query.SetParameter("p_crs", OracleDbType.RefCursor);
query.SetParameter("p_1", 1);
query.SetParameter("p_2", 12345678);
query.SetParameter("p_3", 1);
query.SetDateTime("p_4", null);
query.SetDateTime("p_5", null);
IList result = query.List();
}
}
任何帮助将不胜感激!