我有一个Oracle函数,它返回
的sys_refcursorCREATE OR REPLACE FUNCTION SCOTT.getemployees
RETURN SYS_REFCURSOR
AS
o_cursor SYS_REFCURSOR;
BEGIN
OPEN o_cursor FOR
SELECT EMPNO,
ENAME,
JOB,
MGR,
HIREDATE,
SAL,
COMM,
DEPTNO
FROM emp;
RETURN o_cursor;
END;
/
在我的Entity类中,我声明为
@Entity
@javax.persistence.NamedNativeQuery(name = "getEmp",
query = "{ ? = call getemployees }", resultClass = Employees.class, hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
@Table(name = "EMPLOYEES")
public class Employees {
在DAO我有
@Inject
private SessionFactory sessionFactory;
@Override
public List<Employees> getEmployees() {
List query = new ArrayList<Employees>();
try{
query = sessionFactory.getCurrentSession()
.getNamedQuery("getEmp").list();
}
catch(Exception e){
System.out.println("exception "+e.getMessage());
e.printStackTrace();
}
return query;
}
当我跑步时我会遇到异常,这可能是什么原因?
INFO:Hibernate:{? = call getemployees} SEVERE:org.hibernate.exception.GenericJDBCException:索引:: 1处缺少IN或OUT参数 在org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) 在org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) 在org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129) 在org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
答案 0 :(得分:3)
我设法解决了这个问题。
定义为数字的数据库表列在实体类中声明为int
。
我已将这些更改为Integer
,问题得到了解决。
private Integer deptNo;
public Integer getDeptNo() {
return deptNo;
}
public void setDeptNo(Integer deptNo) {
this.deptNo = deptNo;
}