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: Does Hibernate support stored procedures?
PostPosted: Thu Feb 05, 2004 9:29 pm 
Newbie

Joined: Thu Feb 05, 2004 9:25 pm
Posts: 2
Does anybody know if Hibernate support stored procedures?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 9:47 pm 
Newbie

Joined: Sat Aug 30, 2003 12:37 pm
Posts: 16
You can use Stored Procedures with Hibernate and here's how you do it:

Pseudo code:

Code:

       List foos = new ArrayList();

      String query = "begin ? :=getFoos(?,?,?); end;";

      CallableStatement stmt = null;
      ResultSet rs = null;

      // Open Hibernate session
      Session session = open();

      try {

         stmt = session.connection().prepareCall(query);

         stmt.registerOutParameter(1, OracleTypes.CURSOR);
         stmt.setLong(2, someID.longValue());
         stmt.setLong(3, anotherID.longValue());
         stmt.setString(4, someChar);

         stmt.execute();

         rs = (ResultSet) stmt.getObject(1);

         while (rs.next()) {

            foo = new Foo();
            foo.setPrimaryID(new Long(rs.getLong(1)));
            foo.setFooName(rs.getString(2));

            foos .add(foo);
         }
      }
      catch (Exception e) {
         // Handle your excpetions here
      }

      finally {
         try {
            if (stmt != null) {
               stmt.close();
            }
            if (rs != null) {
               rs.close();
            }
         }
         catch (Exception ex) {
            //Ignore this exception on purpose.
         }
      // Close Hibernate session
         close();
      }



Top
 Profile  
 
 Post subject: Can stored procedures be persisted?
PostPosted: Thu Feb 05, 2004 10:05 pm 
Newbie

Joined: Thu Feb 05, 2004 9:25 pm
Posts: 2
What I actually meant to ask was Can stored procedures be persisted?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 4:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
? How do you want to "persist" stored procedures


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.