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定义如下:
<sql-query name="getUsersByAge" callable="true">
<return alias="user" class="">
<return-property name="id" column="ID"/>
<return-property name="name" column="NAME"/>
<return-property name="age" column="AGE"/>
</return>
{ ? = call getUsersByAge(?) }
</sql-query>
测试程序如下:
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》
posted on 2007-01-03 15:57
Lib 阅读(1590)
评论(0) 编辑 收藏 所属分类:
开源框架