Hibernate调用oracle存储过程的问题

07-05-26 lljch

有这样一张表

create table student(id number,studentname varchar2(20)
<p>

我建了一个函数,根据输入的学生名返回所有匹配的记录

create or replace function getStudentByName(s in varchar2) return sys_refcursor
is
  c_cursor sys_refcursor;
begin
  open c_cursor for select id,studentname from student where name=s;
  return c_cursor;
end;

映射文件是这样的

<class name="ch.businessobjects.Student" table="student">
    <id name="id" type="int" column="id">
      <generator class="identity"/>
    </id>
    <property name="studentName" type="string" column="studentname"/>
</class>
<sql-query name="myquery">
    <return alias="s" class="ch.businessobjects.Student">
      <return-property name="id" column="a"/>
      <return-property name="studentName" column="b"/>
    </return>
    {?=call getStudentByName(?)}
 </sql-query>
<p>

java调用代码是这样的

Query query = session.getNamedQuery("myquery");
query.setParameter(0, OracleTypes.CURSOR);//错误
query.setParameter(1, "张三");//错误
List l = query.list();
Iterator it = l.iterator();
while (it.hasNext())
{
   Student s = (Student) it.next();
   System.out.println(s.getId() + ":" + s.getStudentName());
}
<p>

程序老是在设置参数的地方报错,请问在调用函数时到底该如何设置参数?