EclipseLink:使用IN表类型调用oracle StoredFunc

时间:2018-08-23 09:31:09

标签: oracle eclipselink stored-functions oracle-type

我正在尝试使用eclipselink 2.6.5调用oracle存储函数,该storedfunction具有oracle类型输入。

这是存储的函数:

create or replace function TEST_FUNC(PAR1 IN VARCHAR2, PAR2 IN MY_TYPE_T)
return varchar2 is 
 begin
  if PAR2 is null then
     return (PAR1 || ' 0');  
  else 
     return(PAR1 || ' ' || PAR2.count);    
  end if;
 end TEST_FUNC;

这是类型声明:

CREATE OR REPLACE MY_TYPE_T as table of MY_TYPE_R

CREATE OR REPLACE TYPE MY_TYPE_R as object
(
  COD_P VARCHAR2(3),
  COD_S VARCHAR2(10)
)

这是类型映射:

@Embeddable
@Struct(name="MY_TYPE_R", fields= {"COD_P", "COD_S"})
@PLSQLTable(
    name="MY_TYPE_R",
    compatibleType="MY_TYPE_T",
    nestedType="MY_TYPE_R"  
)
public class MyRecordType {

  @Column(name="COD_P")
  private String codP;

  @Column(name="COD_S")
  private String codS;

  //costructors, getter and setter...
}

这是存储的映射:

@NamedPLSQLStoredFunctionQuery(
    name="testFunc",
    functionName="TEST_FUNC",
    returnParameter=@PLSQLParameter(
            name="RESULT",
            databaseType = "VARCHAR_TYPE"),
    parameters = {
            @PLSQLParameter(name = "firstParam", queryParameter="PAR1", databaseType = "VARCHAR_TYPE"),
            @PLSQLParameter(name = "secondParam", queryParameter="PAR2", databaseType = "MY_TYPE_T"),
    }
)

这是电话:

@Test
public void testFuncTest() {    
  List<MyRecordType> recTypeList = new ArrayList<MyRecordType>();
  MyRecordType rec = new MyRecordType();
  rec.setCodP("PValue");
  rec.setCodS("SValue");
  recTypeList.add(rec);

  Query query = getEM().createNamedQuery("testFunc");
  query.setParameter("firstParam", "FOO"); 
  query.setParameter("secondParam", recTypeList); 

  Assert.assertEquals("FOO 1", query.getSingleResult());
}

执行测试时,我得到: PLS-00306:“ TEST_FUNC”调用中参数的数量或类型错误

实际上阅读了@PLSQTable上的文档,我对树参数有些困惑:

  • 名称
  • compatibleType
  • nestedType

有人有什么建议吗?

1 个答案:

答案 0 :(得分:0)

首先,您需要使用OracleObject批注将字段定义为Oracle对象。对Struct来说有点重复,但是仍然需要。

delay[l][u][v]

对于所需的PLSQLTable

  if (mydata['mode']==="0") {
   this.appRoutes = [
    {
    path: '',
    redirectTo: 'firstPath',
    pathMatch: 'full'
    },
    {
    path: 'firstPath',
    loadChildren: './firstpath.module#FistPathModule'
    },
    {
    path: 'secondPath',
    loadChildren: './secondpath.module#SecondPathModule'
    }
  ]
 } else if (my_data['mode']==="1") {
   this.appRoutes = [
    {
    path: '',
    redirectTo: 'secondPath',
    pathMatch: 'full'
    },
    {
    path: 'secondPath',
    loadChildren: './secondpath.module#SecondPathModule'
    },
  ]
 }

因此名称需要与您函数中的名称匹配。 PLSQL表块看起来正确,我相信OracleObject部分是缺少的组件并导致了错误。