-->
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: How calling a stored procedure with Hibernate
PostPosted: Wed Jan 16, 2008 9:09 am 
Newbie

Joined: Fri Jan 04, 2008 4:23 am
Posts: 7
Hi,

I'm trying to call a stored procedure written on Oracle9 by a JAVA program.

I created a mapping file which contains the following information :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 9 mai 2007 13:50:38 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
    <class name="com.test.bo.TestProc">
        <loader query-ref="test"/>       
        <sql-update>Call PS_UPDATE_TEST()</sql-update>
    </class>
</hibernate-mapping>


The class "TestProc" is the following :

Code:
package com.test.bo;

public class TestProc {
   
    /** Creates a new instance of TestProc */
    public TestProc() {
    }
   
}


The DAO is the following :

Code:
public class TestProcHome extends DaoHelper {
   
    /** Creates a new instance of TestProcHome */
    public void callProc(){         
          Session session = sessionFactory.getCurrentSession();         
                try{
               session.beginTransaction();                             
               session.getNamedQuery("test");
          }catch (Exception e){
               e.printStackTrace();
          }finally{
               session.getTransaction().commit();
               HibernateUtil.closeSession(session);
          }         
    }   
}


But my question is the following :
- Is that necessary to declare a mapping file in order to call simply a stored procedure which is making an update ?
Because I obtain the following error :
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/test/bo/TestProc.hbm.xml

Thanks in advance for any answer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 11:39 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
as far as I know, you cannot call a stored procedure that performs an update, only selects. Hibernate does not like to lose track of the state of its objects, and calling code that modifies the tables outside the scope of Hibernate (such as an updating SP) would cause that.

_________________
Gonzalo Díaz


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.