Hibernate 3 的存储过程查询方式(摘抄)

Hibernate 3 的存储过程查询方式:
首先创建以下Oracal存储过程:
CREATE OR REPLACE FUNCTION getUsersByAge(userAge in NUMBER)
 RETURN
 SYS_PEFCURSOR AS c_user SYS_REFCURSOR;
BEGIN
 OPEN c_user FOR
  SELECT ID,NAME,AGE FROM TUSER WHERE AGE = userAge;
 RETURN c_user;
END;

对应的sql-query定义如下:


 
 
 

{ ? = call getUsersByAge(?) }

测试程序如下:
Query query = session.getNamedQuery("getUsersByAge");
query.setInteger(0,18);

List list = query.list();
Iterator it = list.iterator();
while(it.hasNext()){
 TUser user = (TUser)it.next();
 System.out.println(user.getName());
}

摘自《深入浅出Hibernate》



Lib 2007-01-03 15:57 发表评论

你可能感兴趣的:(sql,C++,c,Hibernate,C#)