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