JPA-使用@NamedStoredFunctionQuery从Oracle存储函数返回引用游标

时间:2018-08-15 19:20:14

标签: java eclipselink jpa-2.1 stored-functions java-stored-procedures

我的目标是调用一个使用EclipseLink @NamedStoredFunctionQuery批注返回REF CURSOR的oracle存储函数。我尚未找到有关如何实现此功能的任何好的文档。我希望对如何正确调用此函数有一些了解。我尝试了许多不同的方法,但这是关于我走了多远。它似乎正在调用该函数,但是出现以下错误:

Call: BEGIN ? := xxlt.xxlt_bpg_std_width_pkg.get_std_rods(p_series_ind=>?, p_style_ind=>?, p_material_ind=>?, p_color_ind=>?); END;
bind => [5 parameters bound]
Query: DataReadQuery(name="GET_STD_RODS" )
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:902)
at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.executeStoredProcedure(DatabasePlatform.java:2366)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:641)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
Truncated. see log file for complete stacktrace
Caused By: java.sql.SQLException: ORA-06550: line 1, column 14:
PLS-00382: expression is of wrong type
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

这是我尝试调用的函数:

FUNCTION get_std_rods (p_series_ind IN varchar2, p_style_ind IN varchar2, p_material_ind IN varchar2, p_color_ind IN varchar2)
return SYS_REFCURSOR IS lref SYS_REFCURSOR;
BEGIN
  OPEN lref FOR
    SELECT bbv.default_rod_mat , bbv.default_rod_color
    FROM xxlt.xxlt_bpg_belt_val bbv
    WHERE bbv.series_ind = p_series_ind AND
          bbv.belt_style_ind = p_style_ind AND
          bbv.material_ind = p_material_ind AND
          bbv.color_ind = p_color_ind AND
          bbv.inactive = 0;
  RETURN lref;
END;

实体类:

 @NamedStoredFunctionQuery(name = "GET_STD_RODS",
                           functionName = "xxlt.xxlt_bpg_std_width_pkg.get_std_rods",
                           parameters = {
                                @StoredProcedureParameter(name = "p_series_ind", queryParameter = "p_series_ind", direction = Direction.IN, type = String.class),
                                @StoredProcedureParameter(name = "p_style_ind", queryParameter = "p_style_ind",  direction = Direction.IN, type = String.class),
                                @StoredProcedureParameter(name = "p_material_ind", queryParameter = "p_material_ind", direction = Direction.IN, type = String.class),
                                @StoredProcedureParameter(name = "p_color_ind", queryParameter = "p_color_ind", direction = Direction.IN, type = String.class),
                           }, returnParameter = @StoredProcedureParameter(name = "lref", queryParameter = "lref", direction = Direction.OUT_CURSOR, type = Cursor.class))

    @Entity
    @Dependent
    @PersistenceUnit(name="DB")
    @Produces("application/json")
public class StandardRods {//implements Serializable{
@Basic
private String default_rod_mat;

public String getDefault_rod_mat()
{
    return default_rod_mat;
}
public void setDefault_rod_mat(String default_material)
{
    this.default_rod_mat = default_material;
}
@Basic
private String default_rod_color;

public String getDefault_rod_color()
{
    return default_rod_color;
}

public void setDefault_rod_color(String default_color)
{
    this.default_rod_color = default_color;
}
@Id
private String seriesInd;

public String getSeriesInd() { return seriesInd; }

public void setSeriesInd(String series) { this.seriesInd = series; }

@Id
private String beltStyleInd;

public String getBeltStyleInd() { return beltStyleInd; }

public void setBeltStyleInd(String style) { this.beltStyleInd = style; }

@Id
private String materialInd;

public String getMaterialInd() { return materialInd; }

public void setMaterialInd(String material) { this.materialInd = material; }

@Id
private String colorInd;

public String getColorInd() { return colorInd; }

public void setColorInd(String color) { this.colorInd = color; }

@Override
public String toString()
{
    return "Default Color : " + default_rod_color + ", Default Material : " + default_rod_mat;
}
}

存储库类:

@Dependent
public class StandardRodsRepo implements StandardRodsDAO{
@PersistenceContext
private EntityManager em;

public List<StandardRods> getDefaultRodAndColor(String seriesInd, String beltStyleInd, String materialInd, String colorInd)
{
    return (List<StandardRods>) em.createNamedQuery("GET_STD_RODS")
            .setParameter("p_series_ind", seriesInd)
            .setParameter("p_style_ind", beltStyleInd)
            .setParameter("p_material_ind", materialInd)
            .setParameter("p_color_ind", colorInd).getResultList();
}

任何有关如何实现这一目标的技巧将不胜感激。

0 个答案:

没有答案