使用休眠调用过程时出现以下异常
Exception in thread "main" org.hibernate.MappingException: Named query not known: loadUserByRank
at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:70)
at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1260)
at dto.TestHB.main(TestHB.java:22)
以下是 Oracle 程序:
create or replace procedure SELECT_USERS_BY_RANK
(
OUT_RESULT out SYS_REFCURSOR,
IN_RANK in int
) as
begin
open OUT_RESULT for
select
u.user_id as user_id,
u.name as name,
u.rank as rank
from
AppUser u
where
u.rank >= IN_RANK;
end;
映射配置代码:
<sql-query name="loadUserByRank" callable="true">
<return class="core.AppUser">
<return-property name="id" column="USER_ID"/>
<return-property name="name" column="NAME"/>
<return-property name="rank" column="RANK"/>
</return>
{ call SELECT_USERS_BY_RANK(?, :rank) }
</sql-query>
执行代码
Query query = session.getNamedQuery("selectAllEmployees_SP");