I have an Oracle stored procedure that I would like to execute that performs several inserts/updates. I did not set up a REF CURSOR return type for the function as the Hibernate documentation states, but I took the following approach instead. One of the reasons that I proceeded as follows is that I need the procedure call to be in the same transactional boundary as several other Hibernate updates, and I did not want to use session.connection() to gain access to the CallableStatement because of method deprecation.
Does anybody have any criticism/comments about grabbing the SessionImplementor interface from the Session and getting the CallableStatement as follows? This all works fine in my test case. I just wanted to know if there are any potential problems with this approach.
Thank you for your feedback.
Code:
String dbProcedureCallSql = "{? = call schema.DB_FUNCTION(?,?,?,?,?,?,?,?)}";
CallableStatement dbProcedureCall =
((SessionImplementor) session).getBatcher()
.prepareCallableStatement(dbProcedureCallSql);
dbProcedureCall.registerOutParameter(1, java.sql.Types.INTEGER);
dbProcedureCall.setLong(2, Long.parseLong(myparms.value1()));
dbProcedureCall.setLong(3,Long.parseLong(myparms.value2()));
dbProcedureCall.setString(4,myparms.value3());
dbProcedureCall.setString(5,myparms.value3());
dbProcedureCall.setString(6,myparms.value4());
dbProcedureCall.setString(7,myparms.value5());
dbProcedureCall.setString(8,null);
dbProcedureCall.setLong(9,Long.parseLong(myparms.value6()));
dbProcedureCall.executeUpdate();
int retVal = dbProcedureCall.getInt(1);