These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Calling Stored Procedure problem
PostPosted: Tue Aug 12, 2008 10:41 am 
Newbie

Joined: Tue Aug 12, 2008 9:27 am
Posts: 1
Hi.I'm new in NHibernate and I'm disapointed in it.It makes my work easier but also complicates it.I need to call a stored procedure that doesn't return all columns from the table,only the columns that i need.
My stored procedure in MySql is:

Code:
CREATE DEFINER=`protocollo`@`%` PROCEDURE `SelectIn`(IN identifier INT)
BEGIN
if identifier = 0 then
      Select Id,ReceivedDate,Recipient,Item,ProtocolNumber,FileName from entrata;
else
    Select * from entrata where Id=identifier;
END IF;
END


and the .hbm file is:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Protocollo.Data" namespace="Protocollo.Data">
  <class name="ProtocolIn" table="entrata" lazy="true">
    <id name="Id" column="Id">
      <generator class="native" />
    </id>
   <property name="ReceivedDate" column="ReceivedDate" type="string"/>
    <property name="Recipient" column="Recipient" />
    <property name="Item"  column="Item"/>
    <property name="ProtocolNumber"  column="ProtocolNumber"/>
    <property name="File" column="File" update="false" insert="false"/>
   <property name="FileName" column="FileName"/>
  </class>
   <sql-query name="SelectAll" >
      <return class="ProtocolIn">
         <return-property name="Id" column="Id"/>
         <return-property name="ReceivedDate" column="ReceivedDate"/>
         <return-property name="Recipient" column="Recipient"/>
         <return-property name="Item" column="Item"/>
         <return-property name="ProtocolNumber" column="ProtocolNumber"/>
         <return-property name="File" column="File"/>
         <return-property name="FileName" column="FileName"/>
      </return>
      call SelectIn(?)
   </sql-query>
</hibernate-mapping>


the C# code:


Code:
ISession session = NHibernateHelper.GetCurrentSession();
            ITransaction tx = session.BeginTransaction();
            IList<object> list = session.GetNamedQuery("SelectAll").SetParameter(0,0).List<object>();
            tx.Commit();
            session.Close();
            NHibernateHelper.CloseSession();
            return list;


when I send a specific Id to get all column it works fine when I put the identifier variable to 0 from store procedure in order to get only the columns that I need I get an error: "Could not find specified column in results".This error appears becouse I've specified the File property in the .hbm file but I need this column for a specific identifier. How can avoid selecting the File column when identifier variable from stored procedure is 0.Please help.Give me some sugestions.
Thank you.
Have a nice day.[/i]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.