2013-01-02 51 views
2

調用StoredProcedure的我寫了下面的存儲過程:與Hibernate

create or replace 
PROCEDURE    SP_GET_NUMBER (p_cursor out sys_refcursor, departmentId in number, userId in number, documentTypeId in number) 
as 
regId integer; 
sqlScript varchar2(60); 
begin 
sqlScript:='select registrationnumber_seq.nextval from dual'; 
execute immediate sqlScript into regid; 
dbms_output.put_line('Nextval is: '||TO_CHAR(regid)); 
insert into roketsanuser.registrationnumbers 
(id, departmentid, documenttypeid, registrationnumber, registrationstatus, status, updatedate, updateuserid, version) 
values 
(regId, null, null, regid, 0, 0, sysdate, 0, 0); 
commit; 
open p_cursor for 
    select * 
     from registrationnumbers reg 
    where reg.id = regid; 
end; 

而且我確定,在我的實體類的註釋中:

@Entity(name = "RegistrationNumber") 
@Table(name = "REGISTRATIONNUMBERS") 
@SequenceGenerator(name = "REGISTRATIONNUMBER_SEQ", sequenceName = "REGISTRATIONNUMBER_SEQ") 
@org.hibernate.annotations.NamedNativeQuery(name = "SP_GET_NUMBER", query = "{call ?= SP_GET_NUMBER(:departmentId, :userId, :documentTypeId)}", 
              callable = true, readOnly = true, resultClass = RegistrationNumber.class) 
@EntityListeners({ BaseEntityListener.class }) 
public class RegistrationNumber extends BaseEntity 

我打電話詢問我的DAO類:

public RegistrationNumber getNumberForIncomingPaperworkByStoredProcedure(EntityManager manager, RegistrationNumber registrationNumber) 
{ 
    Session session = (Session)manager.getDelegate(); 
    org.hibernate.impl.SQLQueryImpl query = (SQLQueryImpl)session.getNamedQuery("SP_GET_NUMBER"); 

    query.setParameter("departmentId", ObjectUtil.isNotNull(registrationNumber.getDepartment()) ? registrationNumber.getDepartment().getId() : ""); 
    query.setParameter("userId", ObjectUtil.isNotNull(registrationNumber.getUser()) ? registrationNumber.getUser().getId() : ""); 
    query.setParameter("documentTypeId", ObjectUtil.isNotNull(registrationNumber.getDocumentType()) ? registrationNumber.getDocumentType().getId() : ""); 
    Collection list=query.list(); 
    return new RegistrationNumber(); 
} 

但是,當我執行查詢發生異常: < 02-01-2013 10:04:24點EET> < 02-01-2013 10:04:27點EET> < 10:04:27,811錯誤[IncomingPaperworkMBean] EJB異常:;嵌套的異常是: org.hibernate.exception.SQLGrammarException:無法執行查詢;嵌套的異常是:org.hibernate.exception.SQLGrammarException:無法執行查詢>

什麼原因,請幫幫我?

回答

0

與Oracle我用的查詢語法

query = "call SP_GET_NUMBER(?, :departmentId, :userId, :documentTypeId)", hints = {@QueryHint(name = "org.hibernate.callable", value = "true")}

,它爲我工作。

+0

感謝您的回覆。但遺憾的是沒有任何改變 – webyildirim