Hi,
I am trying to execute a stored procedure using hibernate.
Below are the snippet from my mapping file
<sql-query name="checkIfContractExists" callable="true" >
<return-scalar type="long" column="rowupdated"/>
{ ? = call checkIfContractExists(?,?,?) }
</sql-query>
The Java code which I am using to invoke the stored procedure
try{
session = HibernateSessionFactory.currentSession();
Query query = session.getNamedQuery( "checkIfContractExists" );
query.setLong(0, 100344 );
query.setLong(1, 143405);
query.setLong(2, 992);
log.debug("before executing the script");
List list = query.list();
log.debug("after executing the script");
Object count = list.get(0);
}
Stored procedure code
create or replace
PROCEDURE checkIfContractExists
(
o_err_flag out SYS_REFCURSOR,
pi_con_mkt_type_combo_id IN number,
pi_union_agmt_id IN number,
pi_pay_method_code IN NUMBER
) IS
v_RecordCount NUMBER;
v_Error_Flag varchar2(1);
v_ContractCount NUMBER;
v_run_pay_method_code NUMBER;
v_onehr_pay_method_code NUMBER;
v_existing_pay_method_code NUMBER;
v_pay_method_runs_flag char(1) ;
BEGIN
--This procedure checks whether the cotract exists for a given market combination
--IF THE CONTRACT exists then check whether it is a runs or one hour method
SELECT count(*) into v_ContractCount FROM RESD_CON_KEY
WHERE con_mkt_type_combo_id = pi_con_mkt_type_combo_id
AND pi_union_agmt_id = pi_union_agmt_id;
select lookup_code_id into v_run_pay_method_code
from resd_lookup_code where lookup_type='Payment Method'
and lookup_code = 'Runs';
select lookup_code_id into v_onehr_pay_method_code
from resd_lookup_code where lookup_type='Payment Method'
and lookup_code = '1 Hour';
IF NVL(v_ContractCount, 0) = 0 THEN
--SET THE ERROR FLAG AS 1 AS THERE ARE NO CONTRACTS FOR THIS MARKET COMBO AND
--UNION AGREEMENT
o_err_flag := 1;
ELSIF NVL(v_ContractCount, 0) = 1 and (pi_pay_method_code = v_run_pay_method_code or pi_pay_method_code = v_onehr_pay_method_code) THEN
---FETCH THE PAY_METHOD_CODE OF THE ALREADY EXISTING CONTRACT TO SEE IF IT IS RUNS OR ONE HOUR
SELECT pay_method_code INTO v_existing_pay_method_code FROM RESD_CON
WHERE con_key_id IN
(
SELECT con_key_id
FROM resd_con_key
WHERE con_mkt_type_combo_id = pi_con_mkt_type_combo_id
AND pi_union_agmt_id = pi_union_agmt_id
);
IF(pi_pay_method_code = v_run_pay_method_code ) THEN
v_pay_method_runs_flag := 'Y';
ELSIF (pi_pay_method_code = v_onehr_pay_method_code) THEN
v_pay_method_runs_flag := 'N';
END IF ;
IF(v_pay_method_runs_flag ='Y' AND v_existing_pay_method_code = v_onehr_pay_method_code) THEN
o_err_flag := 1;
ELSIF(v_pay_method_runs_flag ='N' AND v_existing_pay_method_code = v_run_pay_method_code) THEN
o_err_flag := 1;
ELSE
o_err_flag := -1;
END IF ;
ELSIF NVL(v_ContractCount, 0) = 2 THEN
-- send the error flag as Y as we already have two contracts for this market and we cannot let the user add more.
o_err_flag := -1;
ELSE
o_err_flag := -1;
END IF;
OPEN o_ref_cursor FOR
SELECT o_err_flag AS rowupdated FROM dual;
RETURN o_ref_cursor;
END;
I am getting the results as null when the stored procedure is invoked from the hibernate but when I run the stored procedure from the database I get the correct results.
|