如何使用EclipseLink 2.6 JPA将表对象类型作为IN param传递给Stored Proc

时间:2017-05-11 01:49:24

标签: jpa stored-procedures eclipselink

有人可以帮我弄清楚如何使用EclipseLink JPA将表对象类型作为IN参数传递给存储过程吗?

这是我的存储过程:

create or replace TYPE FORMS_DTLS_TYPE FORCE as OBJECT
(ITEM_ID  NUMBER, STUDY_ID NUMBER, ITEMTYPE VARCHAR2(50),ITEM_TITLE   VARCHAR2(50));
create or replace TYPE FORMS_DTLS_COLL AS TABLE OF FORMS_DTLS_TYPE;

PROCEDURE createForm(pi_form_coll IN FORMS_DTLS_COLL,
                        x_return_status OUT NOCOPY VARCHAR2)
IS
BEGIN
x_return_status := 'SUCCESS';
FOR i in pi_form_coll.FIRST..pi_form_coll.LAST
LOOP
  INSERT INTO TEST_FORMS ("ITEM_ID", "STUDY_ID", "ITEM_TYPE",  "ITEM_TITLE")
  VALUES (pi_form_coll(i).ITEM_ID,   pi_form_coll(i).STUDY_ID,pi_form_coll(i).ITEMTYPE, 'TITLE');
  COMMIT;
 END LOOP;
END createForm;

使用@NamedPLSQLStoredProcedureQuery定义存储过程:

@Entity
@NamedPLSQLStoredProcedureQueries( {   
 @NamedPLSQLStoredProcedureQuery(name = "TestForms.forms", procedureName = "FORMS_DTLS_PKG.createForm",
            parameters = {
                @PLSQLParameter(name = "pi_form_dtls", direction = Direction.IN, databaseType = "FORMS_DTLS_COLL"),
                @PLSQLParameter(name = "x_return_status", direction = Direction.OUT, databaseType = "VARCHAR_TYPE")
            }
    )
})

@Struct(name="FORMS_DTLS_TYPE", fields={"ITEM_ID", "STUDY_ID", "ITEMTYPE", "ITEM_TITLE"})
@PLSQLTable(
   name="FORMS_DTLS_COLL",
   compatibleType="FORMS_DTLS_TYPE"
)
public class TestForms implements Serializable {
...
}

调用存储过程:

public String createTestForm0() throws ServiceException {
    Query query = em.createNamedQuery("TestForms.forms");
    TestForms forms = new TestForms();
    List<TestForms> formList = new ArrayList();                
    forms.setItemId(BigDecimal.valueOf(5));
    forms.setStudyId(BigInteger.valueOf(99));// stuId);
    forms.setItemType("New");
    forms.setItemTitle("New title");
    formList.add(forms);
    query.setParameter("pi_form_dtls", formList);                
    String result = (String)query.getSingleResult();
    return result;
}

我收到以下错误:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Fail to construct descriptor: Unable to resolve type: "ORACLE.FORMS_DTLS_TYPE"
Error Code: 17060
Call: 
DECLARE
  pi_form_dtlsTARGET FORMS_DTLS_COLL;
  pi_form_dtlsCOMPAT FORMS_DTLS_TYPE := :1;
  x_return_statusTARGET VARCHAR(255);
  FUNCTION EL_SQL2PL_1(aSqlItem FORMS_DTLS_TYPE)
  RETURN FORMS_DTLS_COLL IS
    aPlsqlItem FORMS_DTLS_COLL;
  BEGIN
    IF aSqlItem.COUNT > 0 THEN
      FOR I IN 1..aSqlItem.COUNT LOOP
    aPlsqlItem(I) := aSqlItem(I);
  END LOOP;
END IF;
    RETURN aPlsqlItem;
  END EL_SQL2PL_1;
BEGIN
  pi_form_dtlsTARGET := EL_SQL2PL_1(pi_form_dtlsCOMPAT);
  FORMS_DTLS_PKG.createForm2(pi_form_dtls=>pi_form_dtlsTARGET, x_return_status=>x_return_statusTARGET);
  :2 := x_return_statusTARGET;
END;
  bind => [:1 => [oracle.hsgbu.eclinical.designer.dto.TestFormDto@424d058a], x_return_status => :2]
Query: DataReadQuery(name="TestForms.forms" )

0 个答案:

没有答案