-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using stored procedures
PostPosted: Thu May 19, 2005 4:43 am 
Newbie

Joined: Thu May 19, 2005 4:28 am
Posts: 6
Hi all,

I am currently looking into using Hibernate with JBoss (dev platform) and WebLogic (production platform) with an Oracle 9.2.0.4 database.

We have a lot of really complex queries that are burried in stored procedures. The return type of most of these stored procedures is a CURSOR so we can use these stored procedures as named queries. The JDBC layer translates the CURSOR return type into a java.sql.ResultSet and off we go.

Support for stored procedures is on the features list and I have looked through most of the starters docs and found on http://www.hibernate.org/187.html how Hibernate is supporting it. However, since that page starts with: "Currently a scripple-page for me while working on adding custom sql and stored procedure support into hibernate 2.2/3 - and the basic support is now available in CVS." I was wondering if the support is not complete yet.
What worries me also is that the support for stored procedures is limited to inserts, updates and deletes whereas we are also using stored procedures to query objects from the database.
How would my set of stored procedures that query objects, work with Hibernate?

The stored procedures that we have also return a CURSOR that contains the row that was created. Would that be compatible with Hibernate?

Thank you all,

Rudi.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 7:12 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Is there something wrong with the reference documentation "SQL" chapter?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 9:44 am 
Newbie

Joined: Thu May 19, 2005 4:28 am
Posts: 6
Are you referring to chapter 13. Native SQL Queries?

I have read that but that only show me how to run custom select statements and the syntax is still using {cat.*} type of syntax, not ansi sql-92 syntax.

Code:
Query sqlQuery = sess.createSQLQuery("select {cat.*} from cats {cat}", "cat", Cat.class);
sqlQuery.setMaxResults(50);
List cats = sqlQuery.list();


I honestly don't know how to map that onto my stored procedure syntax.

Example stored procedure (simplified to avoid too much details on this post):

Code:
TYPE jobcode_cursor IS REF CURSOR RETURN jobcode%ROWTYPE;
FUNCTION findByPrimaryKey (v_id IN VARCHAR2) RETURN jobcode_cursor
IS
  c jobcode_cursor;
BEGIN
  OPEN c CURSOR FOR
    SELECT id, code, description
       FROM jobcode
     WHERE id - v_id;
  RETURN c;
END;


Calling the stored procedure is done with:
Code:
Connection connection = ...;
CallableStatement statement = connection.prepareCall("BEGIN ? := findByPrimaryKey(?); END;");
statement.setString(1, ...);
statement.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
statement.execute();
java.sql.ResultSet results = (java.sql.ResultSet) statement.getObject(1);
while (results.next()) {
  /* get the various attributes and stuff them in a jobcode business object. */
}
/* Close all database resources. */


Can you tell me how to map that onto acceptable syntax for createSQLQuery(String) please?

Many thanks,

Rudi


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 10:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look closer

http://www.hibernate.org/hib_docs/v3/re ... /#sp_query

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 10:36 am 
Newbie

Joined: Thu May 19, 2005 4:28 am
Posts: 6
Me moron, I have been browsing the online documentation for version 2 all the time.

Sorry guys!


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