tags:

views:

772

answers:

2

I have the following inner class:

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

In the same class i have the following code:

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;
        }

When i run this code i get the following:

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

Where you see "Índice de colunas inválido" its the Portuguese translation of "Invalid Collumn Index"

What am i missing here?

A: 

There may be a problem with the parameter's index (1). May be it should start with 0.

In any case I prefer the use of named parameters in queries (:param instead of ?).

The problem isnt the index since the index starts with 1. also you cant use named parameters in native queries (from the openjpa implementation)
Nuno Furtado
A: 

I've solved the issue by fully implementing the Entity and changing the original native query to a Normal Query. This shouldnt be required but for some reason the implementation seems to baffle this thing up.

Nuno Furtado