我被困在调用存储在oracle中的过程并从Hibernate客户端返回选定的列。
employee3.hbm.xml
<hibernate-mapping>
<class name="Employee" table="employee3">
<id name="eid" column="eid"/>
<property name="fname" column="first_name"/>
<property name="lname" column="last_name"/>
<property name="email" column="email"/>
</class>
<sql-query name="test1" callable="true">
<return alias ="test1" class ="Employee">
<return-property name="fname" column="first_name"/>
<return-property name="lname" column="last_name"/>
</return>
{?=call get_empdetails_assg(?,?)}
</sql-query>
</hibernate-mapping>
testClient.java
Session ses =sf.openSession();
Transaction tx = ses.beginTransaction();
System.out.println("--------------got tx object-----------");
Employee eb =null;
SQLQuery q1=(SQLQuery)ses.createSQLQuery("test1");
System.out.println("--------------q1 processing-----------");
q1.setString(0,"v%");
存储过程:
create or replace procedure get_empdetails_assg(mycursor out sys_refcursor,cond in varchar)
as
begin
open mycursor for
select eb.first_name,eb.last_name from employee3 eb where eb.first_name like cond;
end;
我在尝试使用setString(0,“v%”)在sql中设置cond时出现输出错误
--------------q1 processing----------- Exception in thread "main" java.lang.IllegalArgumentException: No positional parameters in query: test1 at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:442)
请任何输入..厌倦了尝试:(
此致 杰
答案 0 :(得分:0)
您没有正确传递参数,您需要拨打getNamedQuery()
,而不是createSQLQuery()
。
试试这个。
Query query = session.getNamedQuery("test1");
query.setParameter(1, "some_vlaue");
query.setParameter(2, "some_vlaue");
List result = query.list();