代码之家  ›  专栏  ›  技术社区  ›  Nuno Furtado

EJB3本机查询问题

  •  1
  • Nuno Furtado  · 技术社区  · 15 年前

    我有以下内部课程:

    @Entity
        @Table(name = "SATTET0")
        public class SATTET0Key {
            @Column(name="IESTATUT")
            public String       estatut;
            @Column(name="IINICIO")
            public Date dataInicio;   
        }
    

    在同一个类中,我有以下代码:

    Query q = exp.createNativeQuery("SELECT IESTATUT, IINICIO FROM  "
                    + "\n SATTET0  WHERE IESTATUT=? AND DATAFIM IS NULL ", SATTET0Key.class);
            q.setParameter(1, estatuto);
    
            try {
                key = (SATTET0Key) q.getSingleResult();
                return key;
            } catch (NoResultException e) {
                return null;
            }
    

    当我运行此代码时,我得到以下信息:

    javax.ejb.EJBException: EJB Exception: ; nested exception is: 
        <openjpa-1.1.0-r422266:657916 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Índice de colunas inválido
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:105)
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:87)
        at $Proxy0.lookupSATTET0Key(Unknown Source)
        at com.siemens.eori.service.testEstatutoServiceBean.testLookups(testEstatutoServiceBean.java:58)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: <openjpa-1.1.0-r422266:657916 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Índice de colunas inválido
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:813)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:774)
        at kodo.kernel.KodoQuery.execute(KodoQuery.java:43)
        at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:533)
        at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:235)
        at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:300)
        at com.siemens.eori.service.ejb3.session.EstatutoServiceBean.lookupSATTET0Key(EstatutoServiceBean.java:159)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:15)
        at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
        at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:30)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy335.lookupSATTET0Key(Unknown Source)
        at com.siemens.eori.service.ejb3.session.EstatutoServiceBean_jfjn40_EstatutoServiceImpl.lookupSATTET0Key(EstatutoServiceBean_jfjn40_EstatutoServiceImpl.java:297)
        at com.siemens.eori.service.ejb3.session.EstatutoServiceBean_jfjn40_EstatutoServiceImpl_WLSkel.invoke(Unknown Source)
        at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
        at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
        at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
        at weblogic.security.service.SecurityManager.runAs(Unknown Source)
        at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
        at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Caused by: java.lang.Exception: java.sql.SQLException: Índice de colunas inválido
        at org.apache.openjpa.util.Exceptions.replaceNestedThrowables(Exceptions.java:249)
        at org.apache.openjpa.persistence.ArgumentException.writeObject(ArgumentException.java:107)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at weblogic.utils.io.ObjectStreamClass.writeObject(ObjectStreamClass.java:282)
        at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:231)
        at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
        at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1963)
        at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:2001)
        at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2266)
        at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:413)
        at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)
        at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
        at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1963)
        at weblogic.iiop.UnknownExceptionInfo.writeEncapsulation(UnknownExceptionInfo.java:40)
        at weblogic.iiop.ServiceContext.writeEncapsulatedContext(ServiceContext.java:130)
        at weblogic.iiop.UnknownExceptionInfo.write(UnknownExceptionInfo.java:35)
        at weblogic.iiop.ServiceContextList.write(ServiceContextList.java:41)
        at weblogic.iiop.Message.writeServiceContexts(Message.java:230)
        at weblogic.iiop.ReplyMessage.write(ReplyMessage.java:425)
        at weblogic.iiop.Message.flush(Message.java:193)
        at weblogic.iiop.OutboundResponseImpl.writeUncheckedException(OutboundResponseImpl.java:337)
        at weblogic.iiop.OutboundResponseImpl.sendThrowable(OutboundResponseImpl.java:180)
        at weblogic.rmi.internal.BasicServerRef.handleThrowable(BasicServerRef.java:694)
        at weblogic.rmi.internal.BasicServerRef.postInvoke(BasicServerRef.java:650)
        at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:492)
        ... 3 more
    

    在这里,您可以看到“lido”是“无效collunn索引”的葡萄牙语翻译。

    我这里缺什么?

    3 回复  |  直到 11 年前
        1
  •  1
  •   Doctor Jones    11 年前

    您应该这样编写本机查询(使用:1而不是?)其中iestatut=:1

    Query q = exp.createNativeQuery
              (
                  "SELECT IESTATUT, IINICIO FROM \n SATTET0  WHERE IESTATUT=:1 AND DATAFIM IS NULL",
                  SATTET0Key.class
              );
    
    q.setParameter(1, estatuto);
    

    它运作良好。

        2
  •  0
  •   Vitaly Polonetsky    15 年前

    参数的索引(1)可能有问题。也许应该从0开始。

    在任何情况下,我都喜欢在查询中使用命名参数(:param而不是?).

        3
  •  0
  •   Nuno Furtado    15 年前

    我已经通过完全实现实体并将原始本机查询更改为普通查询来解决这个问题。这不应该是必需的,但出于某种原因,实现似乎会阻碍这件事的进行。