我在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应用程序中尝试了相同的代码,它运行正常。
答案 0 :(得分:1)
NamedStoredFunctionQuery是在EclipseLink 2.3.x中引入的,并且根据documentation WebLogic 10.3.3.0随EclipseLink 2.0.2一起提供。
这就是为什么在部署期间忽略注释并且找不到@NamedStoredFunctionQuery中定义的查询。