Hibernate呼叫Oracle的儲存過程

2021-06-21 12:26:18 字數 2340 閱讀 2805

1.plsql **

一:

create

procedure

proc

()begin

select

*from

proctab;

end;

二:
create

procedure proc1(v_no number(4))

begin

select

*from

proc1

where id=

v_no;

end;

2.hibernate 儲存過程呼叫的一種方法是,通過xml傳統的對映方式去呼叫。

-》儲存過程對映和領域模型中的實體的對應關係

xml對映檔案

-》hibernate api 對儲存過程的呼叫

hibernate api code

session ss= hibernatesessionfactory.getsession()     

list li=ss.getnamedquery("getuser").list();     

ss.close();    

session ss= hibernatesessionfactory.getsession()  

list li=ss.getnamedquery("getuser").list();  

ss.close();

-》jdbc api 對儲存過程的呼叫

jdbc 呼叫 

session session =hibernatesessionfactory.getsession();      

connection conn = session.connection();      

resultset rs =null;     

callablestatement call = conn.preparecall("");     

rs = call.executequery();     

rs.close();     

session.close();    

session session =hibernatesessionfactory.getsession();   

connection conn = session.connection();   

resultset rs =null;  

callablestatement call = conn.preparecall("");  

rs = call.executequery();  

rs.close();  

session.close();

-》直接使用 hibernate  createquerysql呼叫儲存過程

createsqlquery

session session =hibernatesessionfactory.getsession();      

sqlquery query = session.createsqlquery("");     

list list =query.list();     

session.close();    

session session =hibernatesessionfactory.getsession();   

sqlquery query = session.createsqlquery("");  

list list =query.list();  

session.close();

-》通過hibernate api或者jdbc,api給儲存過程傳參

傳參1

callablestatement call = conn.preparecall("");     

call.setstring(1, 引數);     

rs = call.executequery();    

callablestatement call = conn.preparecall("");  

call.setstring(1, 引數);  

rs = call.executequery();

1 sqlquery query = session.createsqlquery("");     

2 query.setstring(0, 引數);

3 list list =query.list();

hibernate呼叫儲存過程

drop table if exists user create table user id int 11 not null auto increment,name varchar 16 not null default remark varchar 16 not null default prim...

hibernate呼叫儲存過程

一 建表 drop table if exists user create table user id int 11 not null auto increment,name varchar 16 not null default remark varchar 16 not null default...

hibernate 呼叫儲存過程

create table proctab id int 11 not null auto increment,name varchar 20 age int 11 primary key id 簡單的儲存過程 create procedure proc begin select from proct...