Below is my Oracle stored procedure,
create or replace
PROCEDURE "REPORT_HIBERNATE"(
start_year IN NUMBER,
output_data OUT SYS_REFCURSOR
)
AS
BEGIN
DECLARE
select_query LONG;
BEGIN
select_query :='SELECT
GLOBAL_ID,
PROJECT_NUMBER,
FISCAL_YEAR,
FISCAL_MONTH,
WEEK_END_DATE,
ACTIVITY,
COST_CENTER,
ACTUAL_HOURS,
APPROVED_HOURS,
NORMALIZED_HOURS
FROM TS_TBTIMECARD_WEEKLY_DATA
where FISCAL_YEAR in
(SELECT FISCAL_YEAR
FROM TS_TBTIMECARD_WEEKLY_DATA
where FISCAL_YEAR = ' ||start_year|| '
)';
OPEN output_data FOR select_query;
END;
END REPORT_HIBERNATE;
Below is the Entity class:
@Entity
@SequenceGenerator(name="wkseq", initialValue=1, allocationSize=1)
@Table(name = "TS_TBTIMECARD_WEEKLY_DATA")
@NamedNativeQuery(name = "call_REPORT_HIBERNATE_procedure",
query = "{ CALL REPORT_HIBERNATE(:start_year) }",
resultClass = TimecardWeeklyData.class, hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
public class TimecardWeeklyData {
...
}
DAOImpl:
Query query = sessionFactory.getCurrentSession().getNamedQuery("call_REPORT_HIBERNATE_procedure");
query.setParameter("start_year",2014);
List result = query.list();
I get the following exception: Hibernate: { CALL REPORT_HIBERNATE(?) } org.hibernate.exception.GenericJDBCException: could not execute query ... and Caused by: java.sql.SQLException: Invalid column index
Plz let me know how will I call this stored procedure using Hibernate Annotation in Spring??