-->
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.  [ 2 posts ] 
Author Message
 Post subject: Advanced Stored Procedure Problem
PostPosted: Wed May 07, 2008 5:36 pm 
Newbie

Joined: Wed Aug 01, 2007 10:36 am
Posts: 7
Hibernate version:3.0

Hi, im use Hibernate 3 to persist with Oracle 9i DB.

The stored procedure is the next:

Code:
PROCEDURE TESTSP(CUR_CONCEPTOS OUT TCURSOR,
                Retorno       OUT NUMBER,
                NAME_IN     IN  TABLA_TEST_HIBERNATE.NOMBRE%TYPE)
IS
ln_Error           NUMBER(1):=0;
ln_Ok              NUMBER(1):=1;

BEGIN
          Retorno:=ln_Ok;
                        
        OPEN CUR_CONCEPTOS FOR
              SELECT Q.ID, Q.NOMBRE
               FROM   TABLA_TEST_HIBERNATE Q
               WHERE  Q.NOMBRE = NAME_IN;
      
EXCEPTION
WHEN INVALID_CURSOR THEN
    Retorno:=ln_Error;
WHEN OTHERS THEN
    Retorno:=ln_Error;
END TESTSP;


The SP receive one in parameter NAME_IN, and to OUT parameters a CURSOR and NUMBER for maning exceptions of the SP.

For the Java side i have my POJO called TablaTestHibernate.java with two attributes, id and name (the same of the table TABLA_TEST_HIBERNATE from oracle)

The mapping for my pojo is the next:

Code:
<hibernate-mapping>
   <class
      name="com.lan.gestioncorporativa.dao.hibernate.valueobjects.TablaTestHibernate"
      table="TABLA_TEST_HIBERNATE" schema="EXGCORP">
      <id name="id" type="java.lang.Long" column="ID">
         <generator class="sequence">
            <param name="sequence">
               EXGCORP.GCCC_SEQ_TABLA_HIBERNATE
            </param>
         </generator>
      </id>
      <property name="name" type="java.lang.String">
         <column name="NOMBRE" length="1" />
      </property>
   </class>

   <sql-query name="spHibernate" callable="true">
      <return alias="emp"
         class="com.lan.gestioncorporativa.dao.hibernate.valueobjects.TablaTestHibernate">
         <return-property name="id" column="ID" />
         <return-property name="name" column="NOMBRE" />
      </return>
      { call PKG_TABLAS_CAMPOS.TESTSP(?,?,:NAME_IN) }
   </sql-query>
</hibernate-mapping>


finally i have a junit class to test the call to the stored procedure.

Code:
public void testLlamadaSP(){
    HibernateSessionFactory fact= new HibernateSessionFactory();
    Session sess= fact.getSession();
    Transaction trans= sess.beginTransaction();
   
    List dd=(ArrayList) sess.getNamedQuery("spHibernate").setParameter("NAME_IN", "some_name").list();
   
    assertTrue(dd.size()>0);
   
}


When i run the test i have the next exception.

Code:
org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters: [] [{ call PKG_TABLAS_CAMPOS.TESTSP(?,:name) }]
   at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:141)


This occurs when i receive more parameters from the stored procedure, but when i call de SP with { call PKG_TABLAS_CAMPOS.TESTSP(?,:NAME_IN) } and eliminate the out parameter Retorno that manage posible errors from the stored procedure that works with no problems.

Are correct call SP { call PKG_TABLAS_CAMPOS.TESTSP(?,"?,?.. if are more out parameters":name) }
I need more configurations to support more out parameters.

Any suggestions or help is welcome.

Thanxs a lot
Myself


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 12:29 pm 
Newbie

Joined: Wed May 07, 2008 6:21 pm
Posts: 6
Location: Lakewood, CO
Hi myselftrue,

your error seems similar but a bit different that mine. I also get wrong # of parameters error but I'm not sure what to put into my mapping because the proc I call does not return anything.


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