-->
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.  [ 8 posts ] 
Author Message
 Post subject: Calling PIPELINED function in java...
PostPosted: Wed Nov 22, 2006 9:02 pm 
Newbie

Joined: Wed Nov 22, 2006 5:09 pm
Posts: 8
Hi,

I am new to Hibernate. I need an immediate solution to this unique problem, below is the description and the associated code..

Hibernate version:3

Name and version of the database you are using:Oracle 9.2.1

Below is code for the function


Code:

-- Create object
CREATE OR REPLACE TYPE summaryObject
AS OBJECT
(
  kriName   VARCHAR2(100),
  warningThreshold   VARCHAR2(500),
  reportingThreshold   VARCHAR2(500),
  cycleValue number,
  cycleComment VARCHAR2(1500)
)


-- Create table of the object to store the recordset to be returned
CREATE OR REPLACE TYPE summaryTable
   AS TABLE OF summaryObject

-- Create function
CREATE OR REPLACE
FUNCTION bsl_opr_okri.gen (cycle_id IN NUMBER, business_id IN NUMBER)
   RETURN summarytable PIPELINED
AS

   CURSOR getkriparamdim (kriidpk IN NUMBER)
   IS
      SELECT a.kri_id_pk, b.param_id_pk, c.dim_id_pk
        FROM kri a, kri_param b, kri_dim c
       WHERE a.kri_id_pk = b.kri_id_pk
         AND a.kri_id_pk = c.kri_id_pk
         AND b.calc_include = 'Y'
         AND a.kri_id_pk = kriidpk;


   CURSOR getkriperiod (startperiod IN DATE)
   IS
      SELECT a.collect_cycle_id_pk
        FROM kri_collect_cycle a
       WHERE a.cycle_date BETWEEN ADD_MONTHS (startperiod, -12) AND startperiod;

   CURSOR krisummary (
      kriidpk   IN   NUMBER,
      cycleid   IN   NUMBER,
      paramid   IN   NUMBER,
      dimid     IN   NUMBER
   )
   IS
      SELECT a.cycle_value
        FROM kri_cycle_val a
       WHERE a.kri_id_pk = kriidpk
         AND a.collect_cycle_id_pk = cycleid
         AND a.param_id_pk = paramid
         AND a.dim_id_pk = dimid;

   CURSOR getkriattributes
   IS
      SELECT c.kri_id_pk d, c.kri_name, c.kri_is_lag, c.threshold_comprator,
             c.threshold_val, c.threshold_desc, d.threshold_val,
             d.threshold_desc, d.formula_id_pk, e.kri_data_avil_flag,
             e.kri_comment
        FROM (SELECT a.kri_id_pk, a.org_unit_id_pk, a.kri_name, a.kri_is_lag,
                     b.threshold_comprator, b.threshold_type_id_pk,
                     b.threshold_val, b.threshold_desc, b.formula_id_pk
                FROM kri a, kri_threshold_val b
               WHERE a.kri_id_pk = b.kri_id_pk AND threshold_type_id_pk = 1) c,
             (SELECT a.kri_id_pk, a.kri_name, a.kri_is_lag,
                     b.threshold_comprator, b.threshold_type_id_pk,
                     b.threshold_val, b.threshold_desc, b.formula_id_pk
                FROM kri a, kri_threshold_val b
               WHERE a.kri_id_pk = b.kri_id_pk AND threshold_type_id_pk = 2) d,
             (SELECT a.kri_id_pk, a.kri_name, a.kri_is_lag,
                     b.kri_data_avil_flag, b.kri_comment
                FROM kri a, kri_info b
               WHERE a.kri_id_pk = b.kri_id_pk AND b.collect_cycle_id_pk = 1) e
       WHERE c.kri_id_pk = d.kri_id_pk
         AND c.kri_id_pk = e.kri_id_pk
         AND c.org_unit_id_pk = business_id;

-- Local variables
   vkriidpk            kri.kri_id_pk%TYPE;
   vkriid              kri.kri_id_pk%TYPE;
   vkriname            kri.kri_name%TYPE;
   vkriislag           kri.kri_is_lag%TYPE;
   vkricomparator      kri_threshold_val.threshold_comprator%TYPE;
   vkriwarning         kri_threshold_val.threshold_val%TYPE;
   vkriwarningdesc     kri_threshold_val.threshold_desc%TYPE;
   vkrireporting       kri_threshold_val.threshold_val%TYPE;
   vkrireportingdesc   kri_threshold_val.threshold_desc%TYPE;
   vkriformula         kri_threshold_val.formula_id_pk%TYPE;
   vkridataavai        kri_info.kri_data_avil_flag%TYPE;
   vkrisummaryval      kri_cycle_val.cycle_value%TYPE               DEFAULT 0;
   vkrisummary         kri_cycle_val.cycle_value%TYPE               DEFAULT 0;
   vkricomments        kri_info.kri_comment%TYPE;
   vkridim             kri_dim.dim_id_pk%TYPE;
   vkriparam           kri_param.param_id_pk%TYPE;
   vkricycleid         kri_collect_cycle.collect_cycle_id_pk%TYPE;
   vkricycledate       kri_collect_cycle.cycle_date%TYPE;
BEGIN
   OPEN getkriattributes;

   LOOP
      vkrisummary := 0;

      FETCH getkriattributes
       INTO vkriidpk, vkriname, vkriislag, vkricomparator, vkriwarning,
            vkriwarningdesc, vkrireporting, vkrireportingdesc, vkriformula,
            vkridataavai, vkricomments;

      EXIT WHEN getkriattributes%NOTFOUND;

      OPEN getkriparamdim (vkriidpk);

      LOOP
         FETCH getkriparamdim
          INTO vkriid, vkriparam, vkridim;

         EXIT WHEN getkriparamdim%NOTFOUND;

         CASE vkriformula
            WHEN 2
            THEN
               SELECT a.cycle_date
                 INTO vkricycledate
                 FROM kri_collect_cycle a
                WHERE a.collect_cycle_id_pk = cycle_id;

               OPEN getkriperiod (vkricycledate);

               LOOP
                  FETCH getkriperiod
                   INTO vkricycleid;

                  EXIT WHEN getkriperiod%NOTFOUND;

                  OPEN krisummary (vkriid, vkricycleid, vkriparam, vkridim);

                  vkrisummaryval := 0;

                  FETCH krisummary
                   INTO vkrisummaryval;

                  CLOSE krisummary;

                  vkrisummary := vkrisummary + vkrisummaryval;
               END LOOP;

               vkrisummary := vkrisummary / 12;

               CLOSE getkriperiod;
            ELSE
               OPEN krisummary (vkriid, cycle_id, vkriparam, vkridim);

               vkrisummaryval := 0;

               FETCH krisummary
                INTO vkrisummaryval;

               CLOSE krisummary;

               vkrisummary := vkrisummary + vkrisummaryval;
         END CASE;
      END LOOP;

      CLOSE getkriparamdim;

      PIPE ROW (summaryobject (vkriname,
                               vkriwarningdesc,
                               vkrireportingdesc,
                               vkrisummary,
                               vkricomments
                              ));

   END LOOP;

   CLOSE getkriattributes;
   return;
END;


I want to call this function from java but have no clue how to do so, help in this regards is highly appericated. Please let me know i any more details required.

Thanks,
Amit


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 2:33 pm 
Newbie

Joined: Wed Nov 22, 2006 5:09 pm
Posts: 8
Can anybody please help me with this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 2:54 pm 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
createSQLQuery() lets you execute any SQL native you want...

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 3:18 pm 
Newbie

Joined: Wed Nov 22, 2006 5:09 pm
Posts: 8
Kindly give me an example of the same. When i use createSQLQuery object it creates an invalid exception.

Code:
org.hibernate.exception.SQLGrammarException: could not execute query
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.doList(Loader.java:2148)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
        at org.hibernate.loader.Loader.list(Loader.java:2024)
        at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
        at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
        at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
        at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
        at com.statestr.basel2.oprisk.okri.dao.calculationengine.HibernateCalculationEngineDao.getValues(HibernateCalculationEngineDao.java:66)
        at com.statestr.basel2.oprisk.okri.biz.calculationengine.CalculateEngineServiceImpl.getData(CalculateEngineServiceImpl.java:35)
        at com.statestr.basel2.oprisk.okri.web.kridata.ViewSummaryAction.process(ViewSummaryAction.java:56)
        at com.statestr.basel2.framework.web.common.ApplicationAction.execute(ApplicationAction.java:93)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
        at com.statestr.basel2.framework.web.common.ThreadTransactionFilter.doFilter(ThreadTransactionFilter.java:30)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
        at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
        at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.SQLException: ORA-00904: "FNC_GET_SUMMARY": invalid identifier


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 5:12 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
I think hibernate is executing your SQL without problems. The problem is in the sentence you are executing. The last line of your exception says:

Caused by: java.sql.SQLException: ORA-00904: "FNC_GET_SUMMARY": invalid identifier

So the problem is not with Hibernate but with your sentence and Oracle. Try to execute it on a oracle console and probably you'll get the same result. Fix your sentence first (using oracle directly) and then try again with hibernate.

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 8:26 pm 
Newbie

Joined: Wed Nov 22, 2006 5:09 pm
Posts: 8
Its working perfectly in oracle direct.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 5:29 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Then use

<property name="show_sql">true</property>

and see what SQL is hibernate sending to Oracle and what's the difference with the sentence you want to execute...

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 11:55 am 
Newbie

Joined: Wed Nov 22, 2006 5:09 pm
Posts: 8
I executed the query shown in the debug window in SQLPlus and i get the correct result.

I think i am not calling the function correctly in hibernate or i don't know the syntax to call it..

Please help.


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