I am trying to execute stored procedure in oracle using hibernate.When I call procedure from hibernate the process get called but after that it showing me exception that
ERROR: Cannot perform fetch on a PLSQL statement: next
Here is my stored procedure in oracle :
create or replace PROCEDURE GETREGISTRATIONRECORDS
(
REGID IN NUMBER
)
AS
MY_CURSER SYS_REFCURSOR;
BEGIN
OPEN MY_CURSER FOR
SELECT * FROM REGISTRATION
WHERE ID = REGID;
END GETREGISTRATIONRECORDS;
And in hibernate i have called this procedure as shown bellow :
Registration.java
@NamedNativeQueries({
@NamedNativeQuery(
name="callRegistrationProcedure",
query="call GETREGISTRATIONRECORDS(:regID)",
resultClass=Registration.class)
})
@Entity
public class Registration {
......
}
and in RegistrationDao.java i have below function
@SuppressWarnings("unchecked")
public List<Registration> getFirstName(int id)
{
Query query = SQLFactory.getSession().getNamedQuery("callRegistrationProcedure").setParameter("regID", id);
List<Registration> result = query.list();
for(int i=0; i<result.size(); i++){
Registration stock = (Registration)result.get(i);
System.out.println(stock.getFirstName());
System.out.println(stock.getLastName());
}
return result;
}
But When I execute my application i get following error :
Hibernate: call GETREGISTRATIONRECORDS(?)
Apr 09, 2015 10:45:24 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 17166, SQLState: null
Apr 09, 2015 10:45:24 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Cannot perform fetch on a PLSQL statement: next
Apr 09, 2015 10:45:24 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/SpringHibernateWebApplication] threw exception [Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: Cannot perform fetch on a PLSQL statement: next] with root cause
java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:192)
I have gone through these links but i did not find the solution
java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next. In Hibernate
So please help me to get the the solution.