1

我的 EJB 代码遇到问题。以下是我的代码,部署在 Weblogic 10.3.3 上:

@Entity
@NamedStoredFunctionQuery(name = "MY_FUNCTION", functionName = "apipay",
    parameters = {
        @StoredProcedureParameter(
            queryParameter = "consubflag", name = "consubflag", direction = Direction.IN, type=String.class),
        @StoredProcedureParameter(
            queryParameter = "contrno", name = "contrno", direction = Direction.IN, type=String.class),
        @StoredProcedureParameter(
            queryParameter = "username", name = "username", direction = Direction.IN, type=String.class)
    },
    returnParameter = 
        @StoredProcedureParameter(
            queryParameter = "paymentid", type = String.class)
)
public class MyPayment implements Serializable {

    @Id
    String paymentid;
    String consubflag;
    String contrno;
    String username;
}

以下是我从中调用的 EJB 代码:

Query q = tabsEntityManager.createNamedQuery("MY_FUNCTION");
q.setParameter("consubflag", "S");
q.setParameter("contrno", contrno);
q.setParameter("username", "ATMGTW");

paymentId = (String) q.getSingleResult();

以下是我的persistence.xml:

<persistence-unit name="PU1" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/myDS1</jta-data-source>
        <class>com.MyPayment</class>
</persistence-unit>
<persistence-unit name="PU2" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/myDS2</jta-data-source>
        <class>com.MyRequest</class>
    </persistence-unit>
</persistence>

完整的错误堆栈跟踪是:

java.lang.IllegalArgumentException: NamedQuery of name: My_FUNCTION not found.
        at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:545)
        at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:1145)
        at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:1032)
        at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:71)
        at com.warid.es.onelink.facade.TopUpControllerBean.postPaidPayment(TopUpControllerBean.java:594)

我在 Java SE 应用程序中尝试了相同的代码,它运行良好。

4

1 回答 1

1

NamedStoredFunctionQuery是在 EclipseLink 2.3.x 中引入的,并且根据文档WebLogic 10.3.3.0 是随 EclipseLink 2.0.2 一起提供的。

这就是为什么在部署期间忽略注释并且找不到在 @NamedStoredFunctionQuery 中定义的查询的原因。

于 2012-07-17T07:19:33.190 回答