-->
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.  [ 3 posts ] 
Author Message
 Post subject: stored procedure with IN and OUT parameters in hibernate
PostPosted: Wed Sep 18, 2013 5:18 am 
Newbie

Joined: Wed Sep 18, 2013 5:12 am
Posts: 6
how to call stored procedure with IN and OUT parameters in hibernate?


Top
 Profile  
 
 Post subject: Re: stored procedure with IN and OUT parameters in hibernate
PostPosted: Wed Sep 18, 2013 8:37 pm 
Newbie

Joined: Wed Mar 19, 2008 11:19 am
Posts: 15
Location: Orlando
I am looking to do the same thing when persisting/merging/deleting. So far, I'm exploring the persisters, but nothing simple is popping out.


Top
 Profile  
 
 Post subject: Re: stored procedure with IN and OUT parameters in hibernate
PostPosted: Sat Sep 28, 2013 7:08 pm 
Newbie

Joined: Wed Mar 19, 2008 11:19 am
Posts: 15
Location: Orlando
Greetings,
Not sure if you're looking to call stored procedures via @SqlInsert/@SqlUpdate/@SqlDelete, but I was and found that the simplest solution was to implement a wrapper as a stored procedure which contained only IN params which were in turn passed to the target procedure. In my situation, I had some OUT error params which I examined to determine if I got an error, and if so, raise a signal (syntax may vary) so that the driver throws an exception which you can then catch. I subclassed the dialect (ie. Db2400Dialect) and overrode the buildSQLExceptionConversionDelegate method by copying the SQLExceptionConversionDelegate and added a check like so:
Code:
public class DB2400Dialect extends org.hibernate.dialect.DB2400Dialect {

  @Override
  public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
      ...
     @Override
      public JDBCException convert(SQLException sqlException, String message, String sql) {
        ...
        if (-438 == errorCode && "V0000".equals(sqlState)) {
          ..
          throw new DataAccessException(...);
        }
       
        return null;
      }
     
    };
  }
  ...
}


So, depending on which rdbms you are using, just search for a way to cause the driver to throw an exception and pass a custom SqlState value (5 characters). Hope this helps. Good luck!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.