Hibernate如何执行存储过程?
@Override
public Boolean setVarValue(final String processInstanceId, final String varName,
final String varValue) {
return getHibernateTemplate().execute(new HibernateCallback<Boolean>() {
@Override
public Boolean doInHibernate(Session session) throws HibernateException{
Connection conn = null;
CallableStatement callable = null;
boolean flag = false;
try {
conn = getConnection();
callable = conn.prepareCall("{CALL PROCESS_WARN.set_var_value(?,?,?)}");
callable.setString(1, processInstanceId);
callable.setString(2, varName);
callable.setString(3, varValue);
callable.execute();
flag = true;
} catch (Exception e) {
logger.error("execute procedure PROCESS_WARN.set_var_value mistakes !!!");
e.printStackTrace();
} finally {
try {
if (null != callable)
callable.close();
if (null != conn)
conn.close();
if (null != session)
session.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return flag;
}
});
}
、、、、、、、、、、、、、、、、
@Override
public Map<String, String> startProcess(final String warningFormId,
final String operationClassKey, final String cityOrgId) {
return getHibernateTemplate().execute(new HibernateCallback<Map<String,String>>() {
@Override
public Map<String,String> doInHibernate(Session session) throws HibernateException{
Connection conn = null;
CallableStatement callable = null;
Map<String,String> ret = new HashMap<String,String>();
try {
conn = getConnection();
callable = conn.prepareCall("{CALL PROCESS_WARN.START_PROCESS(?,?,?,?,?)}");
callable.setString(1, operationClassKey);
callable.setString(2, warningFormId);
callable.setString(3, cityOrgId);
callable.registerOutParameter(4, oracle.jdbc.OracleTypes.VARCHAR);
callable.registerOutParameter(5, oracle.jdbc.OracleTypes.VARCHAR);
callable.execute();
ret.put("process_instance_id", callable.getObject(4).toString());
ret.put("new_task_id_list", callable.getObject(5).toString());
} catch (Exception e) {
logger.error("execute procedure PROCESS_WARN.START_PROCESS mistakes !!!");
e.printStackTrace();
if(e.getMessage().indexOf("ORA-20012") != -1){
String [] strTemp = e.getMessage().split("#");
String msg = "未设置下一步骤的执行人!";
if(strTemp.length > 1){
msg = strTemp[1];
}
throw new NoAssigneeException(msg);
} } finally {
try {
if (null != callable)
callable.close();
if (null != conn)
conn.close();
if (null != session)
session.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return ret;
}
});
}