0
我有一个Oracle存储过程:`休眠答Oracle存储过程
create or replace procedure getClientFromAuthentification(myCursorResult out sys_refcursor, login in VARCHAR2, pwd in VARCHAR2) as
num_client NUMBER(6);
compte_epargne VARCHAR2(50);
compte_courant VARCHAR2(50);
nom VARCHAR2(50);
prenom VARCHAR2(50);
adresse VARCHAR2(100);
begin
open myCursorResult for
select client.num_client, client.num_compte_epargne, client.num_compte_courant,
client.nom_client, client.prenom_client, client.adresse_client
from client
where client.login_client = login and client.mdp_client = pwd;
fetch myCursorResult into num_client, compte_epargne, compte_courant, nom, prenom, adresse;
if myCursorResult%ROWCOUNT > 1 then raise TOO_MANY_ROWS;
else if myCursorResult%ROWCOUNT = 0 then raise NO_DATA_FOUND;
end if;
end if;
exception
when TOO_MANY_ROWS then raise_application_error(-20000, 'base corrompue');
when NO_DATA_FOUND then raise_application_error(-20001, 'pas de résultats');
end getClientFromAuthentification;`
我测试了它在Oracle sqldevelopper和正常工作:
`set serveroutput on;
declare
myCursor sys_refcursor;
begin
dbms_output.enable;
getclientfromauthentification(myCursor, 'durant.jean', 'durant.jean1234');
dbms_output.put_line('cursor = ' || myCursor%ROWCOUNT);
end;`
cursor = 1(它发现它:=))
现在我尝试在java端用hybernate来使用这个过程。
映射:
`<hibernate-mapping>
<class name="model.entity.Client">
<id name="num_client" type="int" />
<property name="num_compte_epargne" type="string" />
<property name="num_compte_courant" type="string" />
<property name="nom" type="string" />
<property name="prenom" type="string" />
<property name="adresse" type="string" />
</class>
<sql-query name="getClientFromAuthentification_SP" callable="true">
<return alias="client" class="model.entity.Client" >
<return-property name="num_client" column="NUM_CLIENT"/>
<return-property name="num_compte_epargne" column="NUM_COMPTE_EPARGNE"/>
<return-property name="num_compte_courant" column="NUM_COMPTE_CLIENT"/>
<return-property name="nom" column="NOM_CLIENT"/>
<return-property name="prenom" column="PRENOM_CLIENT"/>
<return-property name="adresse" column="ADRESSE_CLIENT"/>
</return>
{ call getClientFromAuthentification(?, :login, :mdp) }
</sql-query>
</hibernate-mapping>`
当我使用它:
`
ArrayList<Client> clients;
Query q = session.getNamedQuery("getClientFromAuthentification_SP");
q.setString("login", "durant.jean");
q.setString("mdp", "durant.jean1234");
clients = (ArrayList<Client>) q.list();`
我没有错误,但不幸的是列表是空的...
请帮助我
谢谢您的回答,但让我们想象一下,我想用一个指针。它将如何工作? – mlwacosmos 2011-05-12 13:56:40
这是我答案的第一部分!用'%NOTFOUND'替换'%ROWCOUNT'。让我来帮你,我把它添加到我的答案 – bpgergo 2011-05-12 14:57:50
对不起,但我没有看到这一点。 – mlwacosmos 2011-05-13 11:15:50