5 Replies Latest reply on Apr 16, 2008 5:56 AM by jaikiran pai

    problems with @Idclass

    jose luis ferrer Newbie

      well i will explain a bit, i have one table with 3 fields how primary key, i'm using @Idclass and when i'm using any function of .find i get that exception:

      javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.recargaexpress.gestionpro.entity.Apuntes#component[empresa,numeroAsiento, numeroLinea]{numeroLinea=1,numeroAsiento=86, empresa=1}]

      My entity:

      @Entity
      @Table(name="APUNTES")
      @IdClass(ApuntesPK.class)
      public class Apuntes implements Serializable{
      //Claves
      @Id
      @Column(name="EMPRESA")
      private Integer empresa;

      @Id
      @Column(name="NUMERO_ASIENTO")
      private Integer numeroAsiento;

      @Id
      @Column(name="NUMERO_LINEA")
      private Integer numeroLinea;

      private String modificado;
      .......
      others fields and methods get/set

      }

      and in other class file:

      public class ApuntesPK implements Serializable {

      private Integer empresa;
      private Integer numeroLinea;
      private Integer numeroAsiento;

      //private static final long serialVersionUID = 1L;

      public ApuntesPK() {

      }

      public ApuntesPK(int empresa, int numAsiento, int numLinea){
      this.empresa=empresa;
      this.numeroLinea=numLinea;
      this.numeroAsiento=numAsiento;
      }

      ......
      Methods get/set

      @Override
      public boolean equals(Object o) {
      if (o == this) {
      return true;
      }
      else if (o instanceof ApuntesPK ) {
      return empresa==(((ApuntesPK)o).empresa) &&
      numeroAsiento==(((ApuntesPK)o).numeroAsiento)&& numeroLinea==(((ApuntesPK)o).numeroLinea);
      }
      return false;
      }

      @Override
      public int hashCode() {
      return this.numeroLinea ^ this.numeroAsiento ^ this.empresa;
      }
      }

      In my bean method for find:

      public Apuntes buscarApunte(int empresa, int numAsiento, int numLinea) throws RemoteException {

      ApuntesPK pk = new ApuntesPK();
      pk.setEmpresa(empresa);
      pk.setNumeroAsiento(numAsiento);
      pk.setNumeroLinea(numLinea)

      Apuntes sqlb= em.find(Apuntes.class, pk);

      return sqlb;
      }


      And in request from my client:


      Apuntes x= beanremote.buscarApunte(1,86,1);


      If anyone can help me, and sry for my english

        • 1. Re: problems with @Idclass
          jaikiran pai Master

          Can you post some more logs, especially a few lines above this error message? The SQLGrammarException usually prints out very meaningful messages which might help in identifying the issue. Btw, which version of JBoss do you use?

          While posting the logs or code or xml content, remember to wrap it in a code block using the Code button in the message editor window and please hit the Preview button to make sure your post is correctly formatted

          • 2. Re: problems with @Idclass
            jose luis ferrer Newbie

            JBoss 4.2.2, Full message of the error:

            javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.recargaexpress.gestionpro.entity.Apuntes#component[empresa,numeroLinea,numeroAsiento]{numeroLinea=1, numeroAsiento=86, empresa=1}]
             at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
             at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
            Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.recargaexpress.gestionpro.entity.Apuntes#component[empresa,numeroLinea,numeroAsiento]{numeroLinea=1, numeroAsiento=86, empresa=1}]
             at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
             at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:194)
             at org.jboss.ejb3.entity.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:171)
             at com.recargaexpress.gestionpro.session.ContabilidadBalancesBean.buscarApunte(ContabilidadBalancesBean.java:75)
             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:585)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
             at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
             at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
             at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:163)
             at org.jboss.remoting.Client.invoke(Client.java:1634)
             at org.jboss.remoting.Client.invoke(Client.java:548)
             at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
             at $Proxy0.buscarApunte(Unknown Source)
             at com.pruebas.prueba.main(prueba.java:41)
             at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:74)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
             at $Proxy0.buscarApunte(Unknown Source)
             at com.pruebas.prueba.main(prueba.java:41)
            Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.recargaexpress.gestionpro.entity.Apuntes#component[empresa,numeroLinea,numeroAsiento]{numeroLinea=1, numeroAsiento=86, empresa=1}]
             at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
             at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
             at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)
             at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
             at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
             at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
             at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
             at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
             at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
             at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
             at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
             at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
             at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
             at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
             at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)
             at org.jboss.ejb3.entity.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:171)
             at com.recargaexpress.gestionpro.session.ContabilidadBalancesBean.buscarApunte(ContabilidadBalancesBean.java:75)
             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:585)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
             at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
             at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
            Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]El nombre de columna 'numeroLinea' no es válido.
             at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
             at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
             at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
             at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
             at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
             at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
             at com.microsoft.jdbc.sqlserver.tds.TDSCursorRequest.openCursor(Unknown Source)
             at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
             at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
             at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
             at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
             at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:236)
             at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
             at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
             at org.hibernate.loader.Loader.doQuery(Loader.java:674)
             at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
             at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
             ... 47 more
            


            • 3. Re: problems with @Idclass
              jaikiran pai Master

               

              Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]El nombre de columna 'numeroLinea' no es válido.


              This seems to be the root-cause of the exception. I don't understand that language, but you might probably be able to understand what it's trying to say. Btw, do you see any SQL that's generated, somewhere before this exception stacktrace? If yes, can you post it?


              • 4. Re: problems with @Idclass
                jose luis ferrer Newbie

                 

                "jaikiran" wrote:
                Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]El nombre de columna 'numeroLinea' no es válido.


                This seems to be the root-cause of the exception. I don't understand that language, but you might probably be able to understand what it's trying to say. Btw, do you see any SQL that's generated, somewhere before this exception stacktrace? If yes, can you post it?


                it say, the name of the field "numeroLinea" not is correct, but i dont understand coz is the same field as my datebase table.

                That is my database table:

                http://img291.imageshack.us/img291/5455/dibujohl9.jpg

                Before that exception i didnt saw any SQL...

                • 5. Re: problems with @Idclass
                  jaikiran pai Master

                   

                  "lastra" wrote:



                  it say, the name of the field "numeroLinea" not is correct, but i dont understand coz is the same field as my datebase table.



                  I dont think you have a column named "numeroLinea" in your table. I guess, you have a column named NUMERO_LINEA. Looking back at the code that you posted, i guess you will have to move the @Column annotations to the PK class. Something like this:

                  Entity class (remove the @Column annotation from this class for the Ids):
                  @Entity
                  @Table(name="APUNTES")
                  @IdClass(ApuntesPK.class)
                  public class Apuntes implements Serializable{
                   //Claves
                   @Id
                   private Integer empresa;
                  
                   @Id
                   private Integer numeroAsiento;
                  
                   @Id
                   private Integer numeroLinea;
                  
                   private String modificado;
                   .......
                   others fields and methods get/set
                  
                  }


                  The PK class (introduce the @Column annotation on the id columns):
                  public class ApuntesPK implements Serializable {
                  
                   @Column(name="EMPRESA")
                   private Integer empresa;
                  
                   @Column(name="NUMERO_ASIENTO")
                   private Integer numeroLinea;
                  
                   @Column(name="NUMERO_LINEA")
                   private Integer numeroAsiento;
                  
                   //private static final long serialVersionUID = 1L;
                  
                   public ApuntesPK() {
                  
                  }