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: Hibernate and Oracle stored procedure
PostPosted: Wed Aug 23, 2006 6:35 am 
Newbie

Joined: Fri Dec 05, 2003 8:45 am
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2 cr1

Mapping documents:
Code:
<hibernate-mapping default-lazy="false" package="com.joshlia.logic">
    <class name="Department" table="department">
        <id name="id" column="id">
            <generator class="sequence">
                <param name="sequence">dept_seq</param>
           </generator>
        </id>
        <property name="name" column="name" />
        <sql-insert callable="true">{call USP_DEPARTMENT_I(?)}</sql-insert>
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
      session.connection();
      session.beginTransaction();
      
      Department department=new Department();
      department.setName(name);
      
      session.save(department);


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):
Code:
Hibernate:
    select
        dept_seq.nextval
    from
        dual
Hibernate:
    {call USP_DEPARTMENT_I(?)}


Debug level Hibernate log excerpt:
Code:
Aug 23, 2006 5:26:13 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1006, SQLState: 72000
Aug 23, 2006 5:26:13 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-01006: bind variable does not exist

Aug 23, 2006 5:26:13 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [com.joshlia.logic.Department]
   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.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2140)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2503)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:337)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at com.joshlia.Office.createAndStoreDepartment(Office.java:48)
   at com.joshlia.Office.main(Office.java:18)
Caused by: java.sql.SQLException: ORA-01006: bind variable does not exist

   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
   at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
   at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
   at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)
   at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1144)
   at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)
   at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)
   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2876)
   at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2123)
   ... 12 more



Oracle Stored Proc:
Code:
CREATE OR REPLACE PROCEDURE "JOSHUA"."USP_DEPARTMENT_I"
(
      -- id_in in department.id%type,
      name_in in department.name%type,

      result_cursor out TYPES.cursor_type
)

as

begin
      insert into department(
              -- department.id,
           department.name
      )values(
               -- emp_seq.nextval,
            name_in
      );
      
      OPEN result_cursor FOR SELECT 'success' AS status FROM dual;
end;


Dear all,

How do I connect to Oracle Stored Procedure? Can anyone help me regarding this matter?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 6:53 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Try with:
Code:
<sql-insert callable="true">{call USP_DEPARTMENT_I(?,?)}</sql-insert>

Please, don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 5:37 am 
Newbie

Joined: Fri Dec 05, 2003 8:45 am
Posts: 12
Actually I have commented out so there is only one parameter to be inserted.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 5:49 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
I don't know Oracle stored procedures language (PL/SQL?) but looking at your code I suppose comments are two hyphens --

Try with
Code:
CREATE OR REPLACE PROCEDURE "JOSHUA"."USP_DEPARTMENT_I"
(
   id_in in department.id%type,
   name_in in department.name%type
)

as

begin
   insert into department(
      department.id,
      department.name
   )values(
      id_in,
      name_in
   );
end;

and
Code:
<sql-insert callable="true">{call USP_DEPARTMENT_I(?,?)}</sql-insert>


Please, don't forget to rate.


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.