2016-08-25 3 views
0

JPA를 사용하여 Firebird 선택 가능 프로 시저를 호출하려고합니다.JPA를 사용하여 firebird 선택 저장 프로 시저를 호출하는 방법은 무엇입니까?

java.lang.IllegalArgumentException: Named query not found: select a.dol as id, a.out$error_code as error_code from P_TDA_ADD_LINE_TO_BROKER_REP (:IN$DOC,:IN$SHARE, :IN$B_ACC, :IN$S_ACC, :IN$COMMENT) a

at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:665) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344) at com.sun.proxy.$Proxy33.createNamedQuery(Unknown Source) at com.comp.app.TradesUpload.TradesUpload.addLineToBrokerReport(TradesUpload.java:454) at com.comp.app.TradesUpload.TradesUploadTest.addLineToBrokerReport(TradesUploadTest.java:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

  • 는 파이어 버드 선택 절차 JPA를 사용하여 호출 할 수 있습니다 : 그것은 다음 오류를 반환 할 것입니다 호출 한 후

    public void addLineToBrokerReport(Map<String, Object> parametersForAddDealsProc) { 
    
         MapUtils.debugPrint(System.out, "Parameters for procedure", parametersForAddDealsProc); 
    
         String q = "select a.dol as id, a.out$error_code as error_code " + 
          "from ADD_LINE (:IN$DOC," + 
          ":IN$SHARE, " + 
          ":IN$B_ACC, " + 
          ":IN$S_ACC, " + 
          ":IN$COMMENT) a"; 
    
         Query query = em.createNamedQuery(q, CallProcedureResult.class); 
         for (Map.Entry<String, Object> entry : parametersForAddDealsProc.entrySet()) { 
          query.setParameter("\"" + entry.getKey()+ "\"", entry.getValue()); 
         } 
         CallProcedureResult result = (CallProcedureResult) query.getSingleResult(); 
         LOG.info("Error_code = " + result.getError_code() + " dol = " + result.getId()); 
    
        } 
    

    : 방법처럼 보인다?

  • 메서드에 Query query = em.createNamedQuery(q, CallProcedureResult.class);이 있으면 "명명 된 쿼리를 찾을 수 없습니다"라는 이유는 무엇입니까?
+0

선택 가능한 저장 프로 시저는 일반 선택 쿼리처럼 동작하므로 저장 프로 시저처럼 처리 할 필요가 없습니다. CallProcedureResult를 사용하는 것은 불필요한 것 같습니다. –

답변

1

em.createNamedQuery 첫 번째 인수는 NamedQuery (JPQL이 아님)의 NAME이라고 가정합니다. 주석 또는 XML에서 정의한 NamedQuery 자체는 NAME을 지정합니다. 또한 SQL direct (JPQL 대신)를 호출하려는 경우 네이티브 쿼리의 경우 NamedNativeQuery이 필요합니다.

JPA 2.1은 저장 프로 시저를 지원합니다. 그게 내가 아무 생각도 없어 파이어 버드의 일을 호출하는 작업,하지만 당신은 그것을 시도 할 수 있는지 여부도

1

Is it possible to call firebird select procedure using JPA?

예 그렇습니다. 대신 EntityManager#createNativeQuery을 사용할 수 있습니다.

Why "Named query not found" if there is Query query = em.createNamedQuery(q, CallProcedureResult.class); in method?

EntityManager#createNamedQuery의 첫 번째 매개 변수는 NamedQuery해야하며 그렇지 않은, 그것은 귀하의 경우 실제 쿼리입니다.

관련없는 네이티브 쿼리에서 명명 된 매개 변수를 사용하는 것은 Hibernate에서 지원되지만 JPA 구현 (https://stackoverflow.com/a/28829942/5078385)에서 이식 가능하게 사용할 수 없습니다.

+0

만약'em.createNativeQuery (q, CallProcedureResult.class);를 사용하면,'query.setParameter ("IN $ SHARE", parametersForAddDealsProc.get ("IN $ SHARE"))'throws'쿼리 매개 변수 'IN $ SHARE 'less ... (Ctrl + F1) 이 검사는 다음 Persistence 모델 문제를 확인합니다. 명명 된 쿼리를 찾을 수 없습니다. 쿼리 매개 변수를 찾을 수 없습니다.' – May12

+0

이것은 문제였습니다. – May12

+0

이제 로그에서 '최대 절전 모드 : a.dol as id, a.out $ error_code를 ADD_LINE (?,?,?,?,?) a'의 error_code로 선택합니다. 매개 변수는 어디에 있습니까? – May12

관련 문제