码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate如何执行存储过程?

时间:2018-06-27 18:53:26      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:new   SQ   process   state   jdbc   RoCE   tee   types   varname   

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;
}
});
}

Hibernate如何执行存储过程?

标签:new   SQ   process   state   jdbc   RoCE   tee   types   varname   

原文地址:https://www.cnblogs.com/YuyuanNo1/p/9235367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!