0

I am calling a store procedure inside Oracle which has 11 inputs and 3 outputs ,inside Oracle SQL developer it's working great , the following is SQL CODE

set serveroutput on
declare

a number;
b varchar2(1);
c varchar2(200);

begin

RETPK002.Generate_contract(4567120000100008,1,null,1200,null,100,null,0,0,0,6,a,b,c);

dbms_output.put_line(' num contract '||a);
dbms_output.put_line(' num contract '||b);
dbms_output.put_line(' num contract '||c);
end;

output is

 num contract 223
 num contract True
 num contract Contrato Processado Com Sucesso

but when i try to run the same logic inside hibernate the query is working now but i can't receive any output
the following is Hibernate Coding inside DAO class

            int a;
            String b;
            String c;
         Query query = getCurrentSession().createSQLQuery(
"CALL RETPK002.Generate_contract(4567120000100008,1,null,1200,null,100,null,0,0,0,6,:a,:b,:c)");

     query.setParameter("a", a);
     query.setParameter("b", b);
     query.setParameter("c", c);

     List result =query.list();
           System.out.println("Value of a " + a);
           System.out.println("value of b "+ b);
           System.out.println("value of c " + c);

Kindly Help me if anyone know about this thanks.

Faisal
  • 32
  • 2
  • 7
  • check if this helps [http://stackoverflow.com/questions/13239120/whats-the-best-way-to-calling-a-stored-procedure-using-hibernate-in-a-generic-d](http://stackoverflow.com/questions/13239120/whats-the-best-way-to-calling-a-stored-procedure-using-hibernate-in-a-generic-d) – Madhusudana Reddy Sunnapu Feb 13 '16 at 13:10
  • bro i tried that by using session but didn't work for me showing me error org.hibernate.exception.SQLGrammarException: could not execute statement – Faisal Feb 13 '16 at 13:36
  • in my case i have three outputs which i think creating problem .... – Faisal Feb 13 '16 at 13:41
  • @ Madhusudana Reddy Sunnapu bro now query is working but how can i receive the output , when i try to print the output variables it's showing me null. kindly help me if you have any idea , thnxx – Faisal Feb 14 '16 at 04:38
  • Not sure which version of hibernate you are using, but if you are using newer versions (I think > 4.2/4.1) Hibernate has a first class support for calling stored procs using `session.createStoredProcedureCall(...)`. With this we can register the IN/OUT/INOUT parameters with `ProcedureCall.registerParameter(...)`. This looks like a better and cleaner way. – Madhusudana Reddy Sunnapu Feb 14 '16 at 06:22
  • yes my friend i am using the latest version and how my query and in out parameter will change according to session.createStoredProcedureCall ... could you please write that for me .. thanks – Faisal Feb 14 '16 at 06:42
  • Check out examples 6,7,8 at [http://www.programcreek.com/java-api-examples/index.php?api=org.hibernate.procedure.ProcedureCall](http://www.programcreek.com/java-api-examples/index.php?api=org.hibernate.procedure.ProcedureCall) – Madhusudana Reddy Sunnapu Feb 14 '16 at 07:07

0 Answers0