-->
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.  [ 3 posts ] 
Author Message
 Post subject: Nested Cursor Result Sets & StoredProc
PostPosted: Mon Dec 12, 2005 5:32 pm 
Newbie

Joined: Mon Dec 12, 2005 5:15 pm
Posts: 2
I'm trying to make Hibernate play with a storedproceedure that returns a REFCURSOR to a result-set that also contains a nested CURSOR for each of the rows in the first result set. But I'm not sure how to do the mapping for this. Would love some suggestions.

I've simplified the example as much as possible.

thanks for any help.

Hibernate version: 3.0.5

Mapping documents:

Code:
<hibernate-mapping package="com.foo">

   <class name="Event" table="foo_event">
      <id name="id" column="id" type="long">
         <generator class="native"/>
      </id>
      <property name="post_date" type="string"/>
   </class>
   
</hibernate-mapping>


<hibernate-mapping package="com.foo">

   <class name="Message" table="foo_message">
      <id name="id" column="id" type="long">
         <generator class="native"/>
      </id>
      <property name="text" type="string"/>
   </class>
   
   <sql-query name="selectMessageEventWithRef_SP" callable="true">
       <return alias="mesg3" class="Message">
           <return-property name="id" column="ID"/>
           <return-property name="text" column="TEXT"/>           
       </return>
       { ? = call selectMessageWhereId(?) }
   </sql-query>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
           
            session = HibernateUtil.currentSession();
            q = session.getNamedQuery("selectMessageEventWithRef_SP");
            results = q.list();
           
            for (Iterator i = results.iterator(); i.hasNext();) {
                mesg = (Message) i.next();
                /would like to be able to get the list of Events here.
            }


Name and version of the database you are using: Oracle 10g

SQL Stored Proceedure:

Code:
CREATE TABLE foo_message (
        id number NOT NULL,
        text varchar(45) NOT NULL,
        CONSTRAINT foo_message_id_pk PRIMARY KEY (id)
        USING INDEX TABLESPACE USERS
        );

CREATE TABLE foo_event (
        foo_event_id number NOT NULL,
        post_date varchar(45) NOT NULL,
        foo_message_id number NOT NULL,
        FOREIGN KEY (foo_message_id) REFERENCES foo_message(id),
        CONSTRAINT foo_event_id_pk PRIMARY KEY (foo_event_id)
        USING INDEX TABLESPACE USERS
        );

-- the stored proc that returns the nested cursors
CREATE OR REPLACE FUNCTION getMessageEventWithRef
        RETURN SYS_REFCURSOR AS r_ref SYS_REFCURSOR;

        p_id    NUMBER                  := 1;

        begin   
                OPEN r_ref FOR
                         SELECT id, text, CURSOR (SELECT foo_event_id,
                         post_date FROM foo_event)                 
                FROM foo_message
                WHERE id = p_id;

        RETURN r_ref;
        end;
/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 4:44 pm 
Newbie

Joined: Mon Dec 12, 2005 5:15 pm
Posts: 2
Okay, found a previous post on returning 2 result sets from a stored procedure. (951021).

Can I therefore assume that nested cursors are also not supported?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 9:40 am 
Newbie

Joined: Wed Nov 01, 2006 10:54 am
Posts: 14
Can you please let me know where you have assigned the value of input parameter in the samples given below and let me know how you get the result coming in refcursor.

session = HibernateUtil.currentSession();
q = session.getNamedQuery("selectMessageEventWithRef_SP");
results = q.list();

for (Iterator i = results.iterator(); i.hasNext();) {
mesg = (Message) i.next();
/would like to be able to get the list of Events here.
}

i'm not sure about the syntax. Please help me out.


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

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.