-->
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.  [ 4 posts ] 
Author Message
 Post subject: Querying with stored procedure
PostPosted: Tue Mar 14, 2006 10:01 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
Hi,
i'd like to know whether i can use stored procedure which would perform a query and return a collection of persitent instances of some mapped class.
It says in the docs that procedures currently return only scalars and entities. Were there any improvements here?
Thanks in advance.

_________________
www.globalresearch.ca


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 12:12 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
Here is a complete Oracle example:

Java code:
Code:
Query q=sess.getNamedQuery("getPeople");
q.setString (0,"John");
Person p=null;
Iterator itr=q.list().iterator();
while(itr!=null&&itr.hasNext())
{
    p=(Person) itr.next();
   System.out.println("p.PERSON_ID=" + p.getPERSON_ID());
   System.out.println("p.FIRST_NAME=" + p.getFIRST_NAME());
   System.out.println("p.LAST_NAME=" + p.getLAST_NAME());
}


Hibernate Mapping code:

Code:
<hibernate-mapping>
   <class>
....
    </class>

<sql-query name="getPeople" callable= "true">
     <return class="com.xyz.Person" />
        { ? = call getPeople(?) }
</sql-query>

</hibernate-mapping>



Oracle function:

Code:
create or replace function getPeople(arg varchar)
    RETURN SYS_REFCURSOR AS
    st_cursor SYS_REFCURSOR;
    BEGIN

      open st_cursor for
      select * from person where upper(first_name)=upper(arg);

    RETURN  st_cursor;

end;
/

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 2:42 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
check out this posting to see how to close the cursor, after you have iterated through the list...

http://forum.hibernate.org/viewtopic.php?t=956724&highlight=

Hope this helps!

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 4:54 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
Thanks for your reply. I'll try it as soon as possible!

_________________
www.globalresearch.ca


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.