-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with oracle function and Query.list()
PostPosted: Tue Feb 05, 2008 1:36 pm 
Newbie

Joined: Sat Feb 02, 2008 1:53 pm
Posts: 2
Location: Monterrey, Nuevo Leon
Hello, I'm a little stuck with this thing, I have a problem with a function created in oracle that retrieve me a cursor, the main problem is that when I call it whit diferent parameters don't give any results, I try this function in an hibernate-free enviroment and I do get some results, but when I call it in hibernate I have no results.

Hope someone can help, I'm very stuck whit this

Thanks

Hibernate version: 3.0

Mapping documents:
<sql-query name="ObtEquipo" callable="true">
<return alias="equipo" class="mx.com.femsa.sam.model.dao.equipment.EquipmentDescriptionTO">
<return-property name="base" column="BASE"/>
<return-property name="idEquipo" column="ID_EQUIPO"/>
<return-property name="descripcion" column="DESCRIPCION"/>
<return-property name="estatus" column="ESTATUS"/>
<return-property name="ubicacion" column="UBICACION"/>
<return-property name="kmsDisponibles" column="KMS_DISPONIBLES"/>
<return-property name="diasDisponibles" column="DIAS_DISPONIBLES"/>
<return-property name="kmsAcumulados" column="KMS_ACUMULADOS"/>
<return-property name="fechaDisponible" column="FECHA_DISPONIBLE"/>
<return-property name="idGrupoTrabajo" column="ID_GRUPO_TRABAJO"/>
<return-property name="idTipoEquipo" column="ID_TIPO_EQUIPO"/>
</return>
{? = call F_OBT_EQUIPO(:parametros)}
</sql-query>

Code between sessionFactory.openSession() and session.close():
public List getEquipment(IDCard idCard, int equipmentType, String processArea, String screen,
String orderBy, String sort, Object[] parameters, String sqlFunction) {
List lista = new ArrayList();
try{
Query query= getSession().getNamedQuery(sqlFunction);
query.setParameterList("parametros",parameters);
lista = query.list();

}catch(Exception e){
e.printStackTrace();
LogManager.write(e);
}finally {
getSession().close();
}
return lista;
}
Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

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

_________________
César Hermosillo Soto
Web Developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 4:15 pm 
Beginner
Beginner

Joined: Mon Mar 07, 2005 6:23 pm
Posts: 21
Did you remember to declare your OUT paramter?

from the docs:

Quote:
For Oracle the following rules apply:

A function must return a result set. The first parameter of a procedure must be an OUT that returns a result set. This is done by using a SYS_REFCURSOR type in Oracle 9 or 10. In Oracle you need to define a REF CURSOR type, see Oracle literature.


Your hibernate stuff might be fine, the stored proc might be where the problem lies.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 7:14 pm 
Newbie

Joined: Sat Feb 02, 2008 1:53 pm
Posts: 2
Location: Monterrey, Nuevo Leon
Hi Clay, the Oracle function works just fine, I put the out parameter and I can get a list of results from that function from a class like this

public void doQuery() {
Connection conexion = null;
int CURSOR=oracle.jdbc.OracleTypes.CURSOR;
try {
Object object = null;
String funcCall=null;
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@MYORACLEDB", "USR", "PAS");
String parameters = "9839, 1, 3, 4, 1, 'schedule', 1,'ID_ESTATUS_EQUIPO,ID_EQUIPO','asc', 41, 1221,0";
funcCall = formatOracleFunction("F_OBT_EQUIPO ",parameters);
CallableStatement cstmt = conn.prepareCall(funcCall);
cstmt.registerOutParameter(1,CURSOR);
cstmt.execute();
object = cstmt.getObject(1);
if( object instanceof ResultSet ) {
ResultSet rslt = (ResultSet)object;
while(rslt.next()) {
System.out.println(rslt.getString(1));
rslt.next();
}
rslt.close();
}
cstmt.close();
conn.commit();
conn.setAutoCommit(true);
} catch (SQLException sqlException) {
sqlException.printStackTrace();
}finally {
if(conexion!=null) {
try {
conexion.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
}

public String formatOracleFunction(String func, String params) {
StringBuffer aux = new StringBuffer("begin :1 := ");
aux.append(func);
if(params != null) {
aux.append(" (" + params + ");");
}
aux.append(" end;");
return aux.toString();
}

public static void main(String[] args) {
PruebaDAO pruebaDAO = new PruebaDAO();
pruebaDAO.doQuery();
}

but when I call that function from hibernate I have no results, and the Loader isn't been executed, I belive there's something wrong or something that I'm missing

_________________
César Hermosillo Soto
Web Developer


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