我的hibernate.cfg.xml
代碼hibernate.cfg.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
3 <session-factory>
4 <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
5 <property name="connection.driver_class"> NHibernate.Driver.OracleDataClientDriver</property>
6 <property name="connection.connection_string">
7 data source=GXLX193;user id=lxmis;password=lxmis
8 </property>
9 <property name="adonet.batch_size">10</property>
10 <property name="connection.release_mode">auto</property>
11 <property name="show_sql">true</property>
12 <property name="use_outer_join">true</property>
13 <property name="dialect"> NHibernate.Dialect.Oracle10gDialect</property>
14 <property name="command_timeout">10</property>
15 <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
16 <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
17 <property name="hbm2ddl.keywords">none</property>
18 <mapping assembly="Model" />
19 </session-factory>
20 </hibernate-configuration>
我的hbm.xml
.hbm.xml代碼
1<?xml version="1.0" encoding="utf-8"?>
2<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model">
3 <sql-query name="Dualsa">
4 {Call pro_GetAllA(:k)}
5 </sql-query>
6 <sql-query name="aaa">
7 select a.FID as id,
8 a.PARAM_VALUE as va
9 from T_PARAMS a
10 </sql-query>
11</hibernate-mapping>
12
我的錯(cuò)誤代碼
1 class Program
2 {
3 static void Main(string[] args)
4 {
5 ISession _ISeesion = new SessionManager().GetSession();
6 IQuery q = _ISeesion.GetNamedQuery("Dualsa");
7 IList list = q.SetInt32("k", 0).List();
8 }
9 }
錯(cuò)誤信息是:Message="could not execute query\r\n[ {call up_test (:p0,:p1) } ]\r\n Name:pInt - Value:100 Name:pString - Value:hello\r\n[SQL: {call up_test (:p0,:p1) }]"
ORA-00911: invalid character
為了說明我能執(zhí)行其他的,我試了調(diào)用aaa是正常的,可以執(zhí)行有結(jié)果
我的正確代碼
class Program
{
static void Main(string[] args)
{
ISession _ISeesion = new SessionManager().GetSession();
IQuery q = _ISeesion.GetNamedQuery("aaa");
IList list = q.List();//正確有結(jié)果的
}
}
我的儲(chǔ)存過程
1 create or replace procedure pro_GetAllA( my_cursor out sys_refcursor,k int ) as
2 begin
3 open my_cursor for select a.FID as id,
4 a.PARAM_VALUE as va
5 from T_PARAMS a;
6 end pro_GetAllA;
我改用另一種方法了,
<property name="connection.driver_class"> NHibernate.Driver.OracleDataClientDriver</property>
改回原來的OracleClientDriver
去掉Oracle.DataAccess.dll的引用
直接使用
ISession _ISeesion = new SessionManager().GetSession();
IDbCommand _cmd = _ISeesion.Connection.CreateCommand();
_cmd.CommandText = "pro_GetAllA";
_cmd.CommandType = CommandType.StoredProcedure;
System.Data.OracleClient.OracleCommandBuilder.DeriveParameters((System.Data.OracleClient.OracleCommand)_cmd);
IDataReader _IDReader = _cmd.ExecuteReader();
object[] _o = new object[_IDReader.FieldCount];
while (_IDReader.Read())
{
for (int i = 0; i < _IDReader.FieldCount; i++)
_o[i] = _IDReader[i];
}