-->
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: Executing stored procedures Oracle Java
PostPosted: Fri Jan 25, 2008 3:28 pm 
Newbie

Joined: Thu Jan 24, 2008 6:30 pm
Posts: 3
hi everyone!

Im using Oracle 10g and hibernate 3.2.5 this is my code:

Mapping file hibernate:

<class name="mx.uam.hibernate.InfoUser" table="TESTINFOUSER">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="employee" column="EMPLOYEE" type="string"/>
<property name="regionCode" column="REGIONCODE" type="integer"/>
<property name="startDate" column="SDATE" type="integer"/>
<property name="endDate" column="EDATE" type="string"/>
</class>

<sql-query name="testInfoUser" callable="true">
<return alias="InfoUser" class="mx.uam.hibernate.InfoUser"/>
{call selectTestInfoUser_sp(:date)}
</sql-query>

ManejadorUser.java :
private List listaInfoUser(Integer arg1){
Query query;
Session session;

session = sessionFactory.openSession();
query = session.getNamedQuery("testInfoUser").setParameter("date", arg1);

return query.list();
}

Script in Oracle:
CREATE TABLE TESTINFOUSER
(id NUMBER(2) NOT NULL,
employee VARCHAR2(50),
regioncode NUMBER(2) NOT NULL,
sDate NUMBER(2),
eDate VARCHAR2(20), PRIMARY KEY (id))
/
CREATE OR REPLACE PACKAGE Types
AS
TYPE ref_cursor IS REF CURSOR;
END;
/
INSERT INTO TESTINFOUSER (id,employee,regioncode,sDate,eDate)
VALUES (1, 'Jose Fernandez',4,1,'24-JAN-08')
/
CREATE OR REPLACE FUNCTION selectTestInfoUser_sp(startDate IN NUMBER)
RETURN Types.ref_cursor
AS
l_resultSet types.ref_cursor;
BEGIN

OPEN l_resultSet FOR
SELECT id, employee, regioncode, sDate, eDate
FROM TESTINFOUSER
WHERE SDATE = startDate;

RETURN l_resultSet;
END;
/

When I run the application this is the error display:

Hibernate: {call selectTestInfoUser_sp(?)}
1781 [main] INFO org.hibernate.type.IntegerType - could not bind value '1' to parameter: 2; Índice de columna no válido
1796 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 17003, SQLState: null
1796 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Índice de columna no válido
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at mx.uam.hibernate.ManejadorUser.listaInfoUser(ManejadorUser.java:31)
at mx.uam.hibernate.ManejadorUser.main(ManejadorUser.java:37)
Caused by: java.sql.SQLException: Índice de columna no válido
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OraclePreparedStatement.setIntInternal(OraclePreparedStatement.java:4612)
at oracle.jdbc.driver.OracleCallableStatement.setInt(OracleCallableStatement.java:4469)
at org.hibernate.type.IntegerType.set(IntegerType.java:41)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.loader.Loader.bindNamedParameters(Loader.java:1753)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1679)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 8 more
Exception in thread "main"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 7:17 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
No creo que reconozca los parámetros por nombre.
Intenta con el índice numérico.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 7:49 pm 
Newbie

Joined: Thu Jan 24, 2008 6:30 pm
Posts: 3
gonzao_diaz wrote:
No creo que reconozca los parámetros por nombre.
Intenta con el índice numérico.


Lo que pasa es que quiero recuperar ese resultset que me va enviar el stored procedure por medio de hibernate y java. Esta es la forma correcta de poder declarar el stored procedure en el mapping de hibernate?
{? = call selectTestInfoUser_sp(?)} o es:
{call selectTestInfoUser_sp(?)}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 8:29 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Lo que sugieno es declarar el SP así

Code:
{?=call selectTestInfoUser_sp(?)}


y en el código Java

Code:
  session.getNamedQuery("testInfoUser").setDate(arg1);

_________________
Gonzalo Díaz


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.