1

我有以下内部类:

@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

您在哪里看到“Índice de colunas inválido”,它是“无效列索引”的葡萄牙语翻译

我在这里想念什么?

4

3 回答 3

1

您应该这样编写本机查询(使用:1 而不是?) WHERE 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);

它运作良好。

于 2011-06-11T13:42:52.343 回答
0

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

无论如何,我更喜欢在查询中使用命名参数(:param 而不是?)。

于 2009-04-24T20:32:11.770 回答
0

我通过完全实现实体并将原始本机查询更改为普通查询解决了这个问题。这不应该是必需的,但由于某种原因,实现似乎使这件事感到困惑。

于 2009-04-27T12:11:34.973 回答