-->
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.  [ 1 post ] 
Author Message
 Post subject: Problems with Hibernate / Stored Procedures
PostPosted: Wed Apr 19, 2006 2:13 pm 
Newbie

Joined: Sun May 09, 2004 2:45 pm
Posts: 14
I am having trouble executing a Stored Procedure from Hibernate. I can't figure out what this Hibernate error means. Has anyone ever come across this problem before. And if so, how did you solve it. Any help would be great. Thanks in advance.

/tim


This is the error I'm getting:

Code:
     [java] [14:03:05,544] [main] WARN  org.hibernate.util.JDBCExceptionReporter  - SQL Error: 0, SQLState: JZ0SC
     [java] [14:03:05,544] [main] ERROR org.hibernate.util.JDBCExceptionReporter  - JZ0SC: Callable Statement: attempt t
o set the return status as an input parameter.
     [java] org.hibernate.exception.GenericJDBCException: could not execute query
     [java]     at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
     [java]     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
     [java]     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
     [java]     at org.hibernate.loader.Loader.doList(Loader.java:1596)
     [java]     at org.hibernate.loader.Loader.list(Loader.java:1577)
     [java]     at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
     [java]     at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
     [java]     at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
     [java]     at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:603)
     [java]     at Deleteme.main(Deleteme.java:35)
     [java] Caused by: java.sql.SQLException: JZ0SC: Callable Statement: attempt to set the return status as an input pa
rameter.
     [java]     at com.sybase.jdbc2.jdbc.ErrorMessage.raiseError(ErrorMessage.java:544)
     [java]     at com.sybase.jdbc2.jdbc.ParamManager.setParam(ParamManager.java:379)
     [java]     at com.sybase.jdbc2.jdbc.SybPreparedStatement.setParam(SybPreparedStatement.java:1141)
     [java]     at com.sybase.jdbc2.jdbc.SybPreparedStatement.setParam(SybPreparedStatement.java:1134)
     [java]     at com.sybase.jdbc2.jdbc.SybPreparedStatement.setLong(SybPreparedStatement.java:202)
     [java]     at org.hibernate.type.LongType.set(LongType.java:40)
     [java]     at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
     [java]     at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
     [java]     at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1115)
     [java]     at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1177)
     [java]     at org.hibernate.loader.Loader.doQuery(Loader.java:390)
     [java]     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
     [java]     at org.hibernate.loader.Loader.doList(Loader.java:1593)
     [java]     ... 6 more
     [java] Exception in thread "main"
     [java] Java Result: 1


The "hibernate.cfg.xml" looks like:
Code:
   ...
   <mapping resource="DeletemeReturn.hbm.xml" />
   <mapping resource="com/lehman/tims/persist/ZStoredProcedure.hbm.xml" />
   
</session-factory>
</hibernate-configuration>




The Stored Procedure is called from SQL like below. And the name of the returned column is "CallScheduleID":
Code:
EXEC SP_MuniShop_UpdateCallSchedule 1234, '1/1/2007', 100,  2003133, 876876876876



Mapped Class:

Code:
public class DeletemeReturn {
   
   
   private java.lang.Long result;
   

   public java.lang.Long getResult() {
      return result;
   }

   public void setResult(java.lang.Long result) {
      this.result = result;
   }

}



Mapping:
Code:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration.                   -->
<!-- Created Fri Feb 10 17:16:42 EST 2006                         -->
<hibernate-mapping >
   
    <class name="DeletemeReturn" table="SP_MuniShop_UpdateCallSchedule" >
      <id name="result" column="CallScheduleID" type="java.lang.Long" />
        <!-- <property name="result" column="CallScheduleID" type="java.lang.Long"  not-null="true" />
      -->
   </class>
   
</hibernate-mapping>



Client Java Code:

Code:
import java.util.GregorianCalendar;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;

import com.lehman.tims.persist.SpBondlots;
import com.lehman.tims.util.HibernateUtil2;
import com.lehman.tims.util.InfrastructureException;

public class Deleteme {
   
   
   public Deleteme() {
      
      super();
   }
   
   public static void main(String[] args) {
      
      Session session = null;
      try {
         
         session = HibernateUtil2.getSession();
         Query query = session.getNamedQuery( "UpdateCallSchedule" );
         //SQLQuery query = (SQLQuery)session.getNamedQuery( "UpdateCallSchedule" );
         //query.addScalar( "updateResult", new org.hibernate.type.LongType() );
         query.setLong( 0, 1234);
         query.setDate( 1, new GregorianCalendar().getTime() );
         query.setDouble( 2, 123.3 );
         query.setLong( 3, 345 );
         query.setLong( 4, 987 );
         
         Object result = query.uniqueResult();
         
         System.out.print( ">> result > "+ result );
         
      }
      catch( InfrastructureException e ) {
         
         e.printStackTrace();
      }
      finally {
         
         try {
            HibernateUtil2.closeSession();
         }
         catch( InfrastructureException e ) {
            e.printStackTrace();
         }
      }
      
   }
   
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.