1

我是 JPA 的新手,我正在尝试调用 DB2 存储过程。但是,据我所知,正在生成的 SQL 是错误的,因此它失败了。

这是我如何设置存储过程:

@NamedStoredProcedureQuery(name = "getApplVars", procedureName = "prc_get_all_appl_var", resultClasses = ApplVars.class,
    parameters = {@StoredProcedureParameter(mode = ParameterMode.IN, name = "ip_cus_set_c", type = String.class),
            @StoredProcedureParameter(mode = ParameterMode.IN, name = "ip_cps_ver_n", type = Integer.class),
            @StoredProcedureParameter(mode = ParameterMode.OUT, name = "op_sqlstate", type = String.class),
            @StoredProcedureParameter(mode = ParameterMode.OUT, name = "op_sqlcode", type = Integer.class),
            @StoredProcedureParameter(mode = ParameterMode.OUT, name = "op_msg", type = String.class)})

这是我调用存储过程的代码:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("DB1");
        EntityManager em = emf.createEntityManager();
        StoredProcedureQuery spq = em.createNamedStoredProcedureQuery("getApplVars");
        spq.setParameter("ip_cus_set_c","CONS");
        spq.setParameter("ip_cps_ver_n",500);
        spq.getResultList();

根据我在单步执行代码时看到的内容以及日志中的内容,这是我看到的 sql 语句。

调用 prc_get_all_appl_var(ip_cus_set_c = ?, ip_cps_ver_n = ?, op_sqlstate = ?, op_sqlcode = ?, op_msg = ?)

但应该是

调用 prc_get_all_appl_var("CONS",500,?,?,?)

这是堆栈跟踪。

[10/23/13 13:43:15:703 MDT] 00000036 SystemOut O [EL 警告]:2013-10-23 13:43:15.698--UnitOfWork(1084751114)--异常 [EclipseLink-4002](Eclipse 持久性服务 - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseException 内部异常:com.ibm.db2.jcc.am.SqlSyntaxErrorException:DB2 SQL 错误:SQLCODE=-104,SQLSTATE=42601,SQLERRMC= =;ppl_var(ip_cus_set_c;+, DRIVER=4.17.28 Error Code: -104 Call: CALL prc_get_all_appl_var(ip_cus_set_c = ?, ip_cps_ver_n = ?, op_sqlstate = ?, op_sqlcode = ?, op_msg = ?) bind => [5个参数绑定] 查询:ResultSetMappingQuery(name="getApplVars") [10/23/13 13:43:15:707 MDT] 00000036 SystemOut O e:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException 内部异常: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL 错误: SQLCODE= -104, SQLSTATE=42601, SQLERRMC==;ppl_var(ip_cus_set_c;+, DRIVER=4.17.28 错误代码: -104 调用: CALL prc_get_all_appl_var(ip_cus_set_c = ?, ip_cps_ver_n = ?, op_sqlstate = ?, op_sqlcode = ?, op_msg = ?) bind => [5 个参数绑定] 查询:ResultSetMappingQuery(name="getApplVars") [10/23/13 13:43:15:707 MDT] 00000036 SystemErr R javax.persistence.PersistenceException: 异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseException 内部异常:com.ibm.db2.jcc.am。SqlSyntaxErrorException: DB2 SQL 错误: SQLCODE=-104, SQLSTATE=42601, SQLERRMC==;ppl_var(ip_cus_set_c;+, DRIVER=4.17.28 错误代码: -104 调用: CALL prc_get_all_appl_var(ip_cus_set_c = ?, ip_cps_ver_n = ?, op_sqlstate = ?, op_sqlcode = ?, op_msg = ?) bind => [5 个参数绑定] 查询:ResultSetMappingQuery(name="getApplVars") [10/23/13 13:43:15:735 MDT] 00000036 SystemErr R at org.eclipse .persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:378) [10/23/13 13:43:15:735 MDT] 00000036 SystemErr R at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery( QueryImpl.java:260) [10/23/13 13:43:15:735 MDT] 00000036 SystemErr R at org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:316) [10/23/13 13:43:15:735 MDT] 00000036 SystemErr R at org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl.getResultList (StoredProcedureQueryImpl.java:548) [10/23/13 13:43:15:736 MDT] 00000036 SystemErr R at cpstools.CPSToolsServlet.doGet(CPSToolsServlet.java:62) [10/23/13 13:43:15: 736 MDT] 00000036 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:575) [10/23/13 13:43:15:736 MDT] 00000036 SystemErr R at javax.servlet.http.HttpServlet。服务(HttpServlet.java:668)[10/23/13 13:43:15:737 MDT] 00000036 SystemErr R 在 com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1240) [10/23/13 13:43:15:737 MDT] 00000036 SystemErr R 在 com.ibm。 ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:760) [10/23/13 13:43:15:737 MDT] 00000036 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper .java:443) [10/23/13 13:43:15:738 MDT] 00000036 SystemErr R 在 com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1033) [13/10/23 13:43:15:738 MDT] 00000036 SystemErr R 在 com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4499) [10/23/13 13:43:15:738 MDT] 00000036 SystemErr R 在 com.ibm。 ws.webcontainer.osgi.DynamicVirtualHost$2.handleRequest(DynamicVirtualHost.java:282) [10/23/13 13:43:15:738 MDT] 00000036 SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer. java:954) [10/23/13 13:43:15:738 MDT] 00000036 SystemErr R at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:252) [13/10/23 13:43:15:739 MDT] 00000036 SystemErr R 在 com.ibm.ws.http。dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:584) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.executeWork (Worker.java:439) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.run(Worker.java:421) [10/23 /13 13:43:15:739 MDT] 00000036 SystemErr R at java.lang.Thread.run(Thread.java:744) [10/23/13 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseExceptionchannel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:584) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java :439) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13: 43:15:739 MDT] 00000036 SystemErr R at java.lang.Thread.run(Thread.java:744) [10/23/13 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink- 4002](Eclipse 持久性服务 - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseExceptionchannel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:584) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java :439) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13: 43:15:739 MDT] 00000036 SystemErr R at java.lang.Thread.run(Thread.java:744) [10/23/13 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink- 4002](Eclipse 持久性服务 - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseException运行(HttpDispatcherLink.java:584)[10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:439)[10/ 23/13 13:43:15:739 MDT] 00000036 SystemErr R 在 com.ibm.ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13:43:15:739 MDT ] 00000036 SystemErr R at java.lang.Thread.run(Thread.java:744) [10/23/13 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseException运行(HttpDispatcherLink.java:584)[10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:439)[10/ 23/13 13:43:15:739 MDT] 00000036 SystemErr R 在 com.ibm.ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13:43:15:739 MDT ] 00000036 SystemErr R at java.lang.Thread.run(Thread.java:744) [10/23/13 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseException739 MDT] 00000036 SystemErr R 在 com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:439) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R 在 com.ibm。 ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at java.lang.Thread.run(Thread.java:744) [ 2013 年 10 月 23 日 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException739 MDT] 00000036 SystemErr R 在 com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:439) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R 在 com.ibm。 ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R at java.lang.Thread.run(Thread.java:744) [ 2013 年 10 月 23 日 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException739 MDT] 00000036 SystemErr R 在 com.ibm.ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R 在 java.lang。 Thread.run(Thread.java:744) [10/23/13 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5) : org.eclipse.persistence.exceptions.DatabaseException739 MDT] 00000036 SystemErr R 在 com.ibm.ws.threading.internal.Worker.run(Worker.java:421) [10/23/13 13:43:15:739 MDT] 00000036 SystemErr R 在 java.lang。 Thread.run(Thread.java:744) [10/23/13 13:43:15:740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5) : org.eclipse.persistence.exceptions.DatabaseException740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002](Eclipse 持久性服务 - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseException740 MDT] 00000036 SystemErr R 原因:异常 [EclipseLink-4002](Eclipse 持久性服务 - 2.5.1.v20130918-f2b9fc5):org.eclipse.persistence.exceptions.DatabaseException

4

0 回答 0