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