首页 新闻 会员 周边 捐助

NHibernate使用Oracle存储过程 报ORA-00900

0
悬赏园豆:120 [待解决问题]

oracle存储过程:

create or replace PROCEDURE "PD_CUSTOMER"
(
p_VERSION IN CUSTOMER.VERSION%TYPE,p_CUSTOMERID IN CUSTOMER.CUSTOMERID%type
)
IS
BEGIN

    DELETE    FROM CUSTOMER
    WHERE
        CUSTOMERID = p_CUSTOMERID and VERSION= p_version;

END ;
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernateSample.Domain" namespace="NHibernateSample.Domain">
  <class name="Customer" table="Customer" >
    <id name="Id" column="CustomerId"  unsaved-value="0">
      <generator class="native" ></generator>
    </id>
    <version name="Version" column="Version" type="Int32"  unsaved-value="0"></version>
    <component name="Name" class="NHibernateSample.Domain.Name,NHibernateSample.Domain" >
      <property name="FirstName" column="FirstName" type="string" length="50" ></property>
      <property name="LastName" column="LastName" type="string" length="50"></property>
    </component>
    <set name="Orders" table="`Order`" generic="true" >
      <key column="Customer" foreign-key="FK_CustomerOrders"></key>
      <one-to-many class="NHibernateSample.Domain.Order,NHibernateSample.Domain"/>
    </set>
    <sql-delete>exec pd_customer?,?</sql-delete>   
    <!--<property name="FirstName"></property>
    <property name="LastName"></property>-->
    <!--<property name="Version"></property>-->
  </class>
</hibernate-mapping>

数据访问层代码:

 public Customer GetCustomerById(int customerid)
         {
             return _session.Get<Customer>(customerid);
         }
public void DeleteCustomerTransction(Customer cus)
         {
             using (ITransaction tx =_session.BeginTransaction())
             {
                 try
                 {
                     _session.Delete(cus);
                     _session.Flush();
                     tx.Commit();

                 }
                 catch (NHibernate.HibernateException)
                 {
                     tx.Rollback();
                     throw;
                 }
             }
         }

 

测试方法:

 [Test]
        public void DeleteCustomerTest()
        {
            var customer = _sample.GetCustomerById(1);
            _sample.DeleteCustomerTransction(customer);
            var testcustomer = _sample.GetCustomerById(1);
            Assert.IsNull(testcustomer);
        }

报错信息

------ Test started: Assembly: NHibernateSample.Test.dll ------

NHibernate: SELECT customer0_.CustomerId as CustomerId2_0_, customer0_.Version as Version2_0_, customer0_.FirstName as FirstName2_0_, customer0_.LastName as LastName2_0_ FROM Customer customer0_ WHERE customer0_.CustomerId=:p0;:p0 = 1 [Type: Int32 (0)]
NHibernate: UPDATE "Order" SET Customer = null WHERE Customer = :p0;:p0 = 1 [Type: Int32 (0)]
NHibernate: exec pd_customer:p0,:p1;:p0 = 1 [Type: Int32 (0)], :p1 = 1 [Type: Int32 (0)]
Test 'NHibernateSample.Test.CRUDWithTransctionTest.DeleteCustomerTest' failed: NHibernate.Exceptions.GenericADOException : could not delete: [NHibernateSample.Domain.Customer#1][SQL: exec pd_customer?,?]
  ----> System.Data.OracleClient.OracleException : ORA-00900: ?? SQL ??

    在 NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Int32 j, Object obj, SqlCommandInfo sql, ISessionImplementor session, Object[] loadedState)
    在 NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Object obj, ISessionImplementor session)
    在 NHibernate.Action.EntityDeleteAction.Execute()
    在 NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
    在 NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
    在 NHibernate.Engine.ActionQueue.ExecuteActions()
    在 NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
    在 NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
    在 NHibernate.Impl.SessionImpl.Flush()
    CRUDWithTransction.cs(54,0): 在 NHibernateSample.DataAccess.CRUDWithTransction.DeleteCustomerTransction(Customer cus)
    CRUDWithTransctionTest.cs(71,0): 在 NHibernateSample.Test.CRUDWithTransctionTest.DeleteCustomerTest()
    --OracleException
    在 System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc)
    在 System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals)
    在 System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor)
    在 System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
    在 NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
    在 NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Int32 j, Object obj, SqlCommandInfo sql, ISessionImplementor session, Object[] loadedState)

0 passed, 1 failed, 0 skipped, took 1.93 seconds (NUnit 2.5.5).
杀猪三刀的主页 杀猪三刀 | 初学一级 | 园豆:82
提问于:2013-11-13 17:30
< >
分享
所有回答(2)
0

以前也遇到过,不知道是不是同一个问题

angelshelter | 园豆:9914 (大侠五级) | 2013-11-13 21:21

怎么解决?

支持(0) 反对(0) 杀猪三刀 | 园豆:82 (初学一级) | 2013-11-14 10:31

@杀猪三刀: 

http://www.baidu.com/s?wd=oracle%20ora-00900&f=12&rsp=0&oq=orale%20ORA-00900&tn=maxthon2&ie=utf-8&ch=3

 

 无效的sql语句,检查一下sql有没有拼错。

支持(0) 反对(0) angelshelter | 园豆:9914 (大侠五级) | 2013-11-15 09:13

@angelshelter: sql语句都是在存储过程中,而且存储过程可以正常运行

支持(0) 反对(0) 杀猪三刀 | 园豆:82 (初学一级) | 2013-11-15 11:10

@杀猪三刀: 那你是不是以存储过程的方式运行的???我记得以前java分slq,预编译,存储过程3种方式执行。。。

支持(0) 反对(0) angelshelter | 园豆:9914 (大侠五级) | 2013-11-15 13:30
0
[秦时明月] | 园豆:738 (小虾三级) | 2013-11-14 10:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册