NHibernate通过ref_cursor从存储过程获取数据
我还无法通过 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();
}
}
任何帮助将不胜感激!
I'm also having trouble to get data from Stored Procedure through ref_cursor .
Maybe you could advise how did you resolve that issue -
My error :
"ORA-06553: PLS-306: wrong number or types of arguments in call to 'GET_SAMPLE_LIST'"}
I suppose The types of arguments in call is the problem
Here is my code :
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>
The SAmple entity :
public class Sample
{
public virtual int Id { get; set; }
public virtual int Makat8 { get; set; }
public virtual int SerialNumber { get; set; }
}
Session configuration - it's Fluent but still the same :
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();
There's the test :
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();
}
}
Any help will be appreceated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自从我在 Oracle 中使用 NHibernate 以来已经有一段时间了,但我似乎记得一些事实,除非 ref_cursor 存储过程参数的名称是一个特定值(尝试沿着这些线进行谷歌搜索),否则它不起作用,是过程的第一个参数(就像你的一样)。
It's been a while since I've used NHibernate with Oracle, but I seem to remember something about the fact that it didn't work unless the name of the ref_cursor stored procedure parameter was a specific value (try to google along those lines), and was the first parameter of the proc (as yours is).
REF CURSOR
必须是过程中的第一个参数 (pCursor OUT ReferenceCursor
):Package Body:
以及您的映射 XML:
现在您可以简单地查询使用这个:
您可以在此处找到更好的解释。
这篇文章可能会帮助您理解一些事情。
REF CURSOR
must be the first parameter in your procedure (pCursor OUT ReferenceCursor
):Package Body:
and your mapping XML:
Now you can simply query using this:
You can find a better explanation here.
This article might help you to understand things.