-->
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.  [ 1 post ] 
Author Message
 Post subject: Stored Procedure Flexibility in Hibernate?
PostPosted: Tue Nov 20, 2007 3:22 pm 
Newbie

Joined: Thu Mar 08, 2007 10:44 pm
Posts: 5
Hibernate version: 3.2.5
Oracle version: 10g

I am working with legacy code where a lot of the logic and access control are in stored procedures. Many of the stored procedures do not follow Hibernate's rules/limitations http://www.hibernate.org/hib_docs/v3/reference/en/html/querysql.html. For example, the stored function I want to call returns a sequence number instead of the number of rows inserted.

Code:
FUNCTION INSERTLOGENTRY
(
    pLogEntryType_CD IN LOGENTRY.LOGENTRYTYPE_CD%TYPE,
    ...
)
    RETURN  NUMBER
IS
    vRet LOGENTRY.LOGENTRY_GN%TYPE;
BEGIN
   
   INSERT INTO LogEntry(LogEntryType_CD, ... )
   VALUES
        (pLogEntryType_CD, ... );

   SELECT LogEntry_SEQ.currVal INTO vRet FROM DUAL;
   RETURN vRet;
END;


To call the function, I use this code

Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
Connection conn = session.connection();
try
{   
   CallableStatement cs =
          conn.prepareCall("{? = call nis.insertlogentry(?,?,?,?,?,?,?,?,?,?)}");
   cs.registerOutParameter(1, Types.NUMERIC);
   cs.setString(2, "DEBUG");
        ...
   cs.execute();
}
catch (SQLException se)
{
   System.out.println("failed callablestatement " + se.getMessage());
}
   
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();


I chose to get the connection from the session because I wanted to use jdbc because it is flexible when it comes to stored procedures. However, I noticed that the session.connection() is deprecated, which worried me.

My questions are:

1) Why is getting the connection from the session deprecated and what are the dangers of getting the connection from the session?

2) Are there issues in the way I execute the stored function in my code?

3) How should I call a stored procedure that does not follow Hibernate's rules and limitations in a framework that uses Hibernate?


Thank you,

Marc


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.