-->
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: Procédures stockées DB2 AS400
PostPosted: Fri Sep 29, 2006 9:25 am 
Newbie

Joined: Fri Dec 09, 2005 5:16 am
Posts: 5
Hibernate version: 3.1

Je ne parviens pas à utiliser une procédure stockée DB2 (AS400).
Par contre ça marche très bien avec Oracle.


Ma procédure DB2 AS400 :
CREATE PROCEDURE PJ/PDA_TEST1(OUT LABEL CHARACTER,IN CEAN
CHARACTER) RESULT SETS 1 LANGUAGE SQL BEGIN DECLARE cursor1 CURSOR
WITH RETURN FOR SELECT LARTar FROM b33stfc/ftartp00 WHERE
cidiar='001' and nartar=cean; SELECT LARTar INTO LABEL FROM
b33stfc/ftartp00 WHERE cidiar='001' and nartar=cean; OPEN cursor1;
END


Mapping :
<sql-query name="getValueSeuleFromCode" callable="true">
<return-scalar column="value" />
<return-scalar column="cod" />
{ ? = call PJ/PDA_TEST1(?,?) }
</sql-query>


Cas d'utilisation :
Session session = HibernateUtil.getSession();
Transaction tx = null;
try {
tx= session.beginTransaction();

Query q = session.getNamedQuery("getValueSeuleFromCode");

q.setString(0, "7610004567015");

List l = q.list();
Object[] tabObj = (Object[]) l.get(0);
System.out.println(l.size() + "RESULTAT = " + tabObj[0]);

tx.commit();
} catch (Exception ex) {
ex.printStackTrace();
if (tx != null) tx.rollback();
} finally {
session.close();
}


Erreur :

Hibernate:
{ ? = call PJ/PDA_TEST1(?,?) }

29 sept. 2006 15:08:42 org.hibernate.util.JDBCExceptionReporter
WARNING: SQL Error: -99999, SQLState: HY105
29 sept. 2006 15:08:42 org.hibernate.util.JDBCExceptionReporter
SEVERE: Parameter type not valid.



Je suis au bord de la dépression... Au secours !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 4:23 am 
Newbie

Joined: Fri Dec 09, 2005 5:16 am
Posts: 5
Mon problème est réglé :



Avec la procédure suivante :



CREATE PROCEDURE PJ/PDA_TEST(IN noart DECIMAL)

RESULT SETS 1 LANGUAGE SQL

BEGIN



DECLARE myCursor CURSOR WITH RETURN FOR SELECT LARTAR FROM B33STFC/FTARTP00 WHERE CIDIAR='001' AND NARTAR=noart;

OPEN myCursor;



END







Mapping hibernate :






<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >



<hibernate-mapping>



<sql-query name="myStoredProcedure" callable="true">

<return-scalar column="LARTAR" type="string"/>

{ call PJ/PDA_TEST(?) }

</sql-query>



</hibernate-mapping>





Cas utilisation :





Session session = HibernateUtil.getSession();

Transaction tx = null;

try {

tx= session.beginTransaction();



Query q = session.getNamedQuery("myStoredProcedure");

q.setLong(0,20150);

List l = q.list();



String resultat = (String) l.get(0);

System.out.println(resultat);





tx.commit();

} catch (Exception ex) {

ex.printStackTrace();

if (tx != null) tx.rollback();

} finally {

session.close();

}





Résultat :

Hibernate: { call PJ/PDA_TEST(?) }

TEQUILA 75CL


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.