-->
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.  [ 5 posts ] 
Author Message
 Post subject: Calling Oracle stored procedures
PostPosted: Mon Aug 27, 2007 6:56 am 
Newbie

Joined: Mon Jul 30, 2007 5:03 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents: Hibernate.cfg.xml , NamedQueries.hbm.xml
Name and version of the database you are using: Oracle 10g Express Edition

Read this: http://hibernate.org/42.html




Hello ,


I have been having quite some trouble now with some oracle stored procedures . I know there have been a lot talks about this subject but it seems none of them were helpful .

Here is my code :



Code:

      Session session = HibernateUtil.getCurrentSession();
      
      logger.debug("Running stored procedure REFRESH_KPIS()");
      
       Query exit_status_query = session.getNamedQuery("refresh_kpis_table");
      
       exit_status_query.setString("fromdate", fromdate);
       exit_status_query.setString("todate", todate);
       logger.debug("query :"+exit_status_query.toString());
       logger.debug("Getting list() ;");
      
       List exit_status = exit_status_query.list();



My NamedQueries.hbm.xml mapping file contains the following :
Code:
   </sql-query>
    <sql-query name="refresh_kpis_table" callable="true">
   { call REFRESH_KPIS( ? , :fromdate , :todate ) }
  </sql-query>


My stored procedure looks like this :
Code:


create or replace
PROCEDURE REFRESH_KPIS ( exit_status out sys_refcursor, from_date in varchar2, to_date in varchar2 )
AS
BEGIN
  DECLARE
  -- Declaration of variables ,...
  BEGIN
  open exit_status for
  select 1 from dual;
  --dbms_output.put_line('from_date '||from_date||' to_date: '||to_date);
  END;
END REFRESH_KPIS;



The exception is quite a general one :

Caused by: java.sql.SQLException: ORA-06550: line 1, column 13:
PLS-00306: wrong number or types of arguments in call to 'REFRESH_KPIS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored


If anyone has tried executing procedures or has any sugestion please help . I've been trying to get those to work for quite some time .


Top
 Profile  
 
 Post subject: Solved it ...
PostPosted: Thu Aug 30, 2007 9:41 am 
Newbie

Joined: Mon Jul 30, 2007 5:03 am
Posts: 8
If anyone has problems using a procedure follow the above code with this slight modification in your named query :
Code:
    <sql-query name="refresh_kpis_table" callable="true">
    <return-scalar column="status" type="integer"></return-scalar>
   { call REFRESH_KPIS( ? , :fromdate , :todate) }
  </sql-query>



The thing is i did not set up a return type for the parameter returned by the procedure ( in my case an exit status ... integer ) .


Top
 Profile  
 
 Post subject: stored procedure
PostPosted: Thu Aug 30, 2007 2:24 pm 
Newbie

Joined: Thu Aug 30, 2007 2:10 pm
Posts: 6
As a SP may have a select statement with joins to multiple tables, how would we do the mapping for the same?


Top
 Profile  
 
 Post subject: Simple
PostPosted: Sat Sep 08, 2007 2:54 pm 
Newbie

Joined: Mon Jul 30, 2007 5:03 am
Posts: 8
just substitute the return types for the columns :


Code:
    <sql-query name="refresh_kpis_table" callable="true">
    <return-scalar column="status" type="integer"></return-scalar>
    <!-- EXAMPLE
    <return-scalar column="column_name1" type="string"/>
     <return-scalar column="column_name2" type="integer"/>
     .

   { call REFRESH_KPIS( ? , :fromdate , :todate) }
  </sql-query>


or check this out :
http://forum.hibernate.org/viewtopic.ph ... =procedure[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 2:17 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Get the connection from session and use that connection as you were using earlier

_________________
Dharmendra Pandey


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