我正在尝试使用hibernate在oracle中执行存储过程。当我从hibernate调用过程时,进程被调用但是之后它显示异常
ERROR: Cannot perform fetch on a PLSQL statement: next
这是我在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;
在hibernate中我调用了这个过程,如下所示:
Registration.java
@NamedNativeQueries({
@NamedNativeQuery(
name="callRegistrationProcedure",
query="call GETREGISTRATIONRECORDS(:regID)",
resultClass=Registration.class)
})
@Entity
public class Registration {
......
}
并在 RegistrationDao.java 我有以下功能
@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;
}
但是当我执行我的应用程序时,我得到以下错误:
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)
我已经浏览了这些链接,但我找不到解决方案
java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next. In Hibernate
所以请帮我解决问题。
答案 0 :(得分:0)
我得到了解决方案。以下代码中所做的更改
oracle中的存储过程:
create or replace PROCEDURE GETREGISTRATIONRECORDS
(
MY_CURSER OUT SYS_REFCURSOR,
REGID IN NUMBER
) AS
BEGIN
OPEN MY_CURSER FOR
SELECT * FROM REGISTRATION
WHERE ID=REGID;
END GETREGISTRATIONRECORDS;
Registration.java 中的
@NamedNativeQuery(
name="callRegistrationProcedure",
query="call GETREGISTRATIONRECORDS(?,:regID)",
callable=true,
resultClass=Registration.class)
@Entity
public class Registration {
......
}
无需对RegistrationDao.java
进行任何更改
我得到了所需的output.Records从oracle数据库中成功获取。