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: switching from JDBC to Hibernate
PostPosted: Thu Sep 01, 2005 7:36 pm 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
How would you go about changing this code to Hibernate style mapping/code
Database Oracle
Code:
      Connection con = DriverManager.getConnection(url, user, pass);
      CallableStatement cstmt = con.prepareCall("{ call ? := random }");
      cstmt.registerOutParameter(1, OracleTypes.CURSOR);
      cstmt.execute();
      OracleCallableStatement stmt = (OracleCallableStatement) cstmt;
      if(stmt == null) {
            System.out.println("Could not cast to OracleCallableStatement");
      }
      ResultSet rs = stmt.getCursor(1);
                                while (rs.next()) {
                                  System.out.println (rs.getInt(1) + " " + rs.getString(2));
                                }


Function
Code:
CREATE OR REPLACE FUNCTION RANDOM RETURN SYS_REFCURSOR
IS
_cursor SYS_REFCURSOR;
BEGIN
  OPEN _cursor FOR SELECT 1 as NUM, 'A' as VAL FROM DUAL;
RETURN _cursor;
END RANDOM;


any suggestion welcome.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 11:38 pm 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
Here is the solution just in case, I had problem because of wrong hibernate3.jar file

Code:

{call ? := random }
or
{? = call random}
are same and have no impact, Oracle included.
also with functions and procedures if you don't pass any data, you don't need () or alternatively you can put it

there is no equivalent of registerOutParameter


mapping xml file
Code:
<sql-query name="select">
<return-scalar column="num" type="long"/>
<return-scalar column="val" type="string"/>
{? = call random()}
</sql-query>


in java
Code:
Session session = ...
Query query = session.getNamedQuery("select");
//will execute and return the resultsets as List
List list = query.list();
Object items[] = (Object[]) list;
System.out.println (items[0]  +  " " + items[1]);


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.