3 Replies Latest reply on May 14, 2002 3:15 AM by casanova

    java.lang.Error: id may not be null / Column 'plant_id' cann

    ewlyahoocom

      Hello,

      I'm trying to create some entity beans. I can load them out of my database (using findAll() for example) but when I try to create() a new one I get various errors all seeming to do with some values not getting set (I've pasted one such exception below). I initially got these errors with the 2.2 version so I am now getting the CVS source and compiling but I still get the errors. I've tried it with and without the CMP stuff, with and without the new EJB 2.0 DOCTYPE, with and without MySQL, with different primary keys, with and without "not null" restrictions on the databsae tables but I can't get anything to work.

      I've even tried debugging the JBoss server. In org.jboss.ejb.plugins.CMPPersistenceManager.createEntity at about line 219 the line:

      Object id = store.createEntity(m, args, ctx);

      sets id to null. I've traced down into the call and find that org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute at about line 68:

      id = entity.extractPrimaryKeyFromInstance(ctx);

      is setting id to null.

      Can anyone suggest a way I might get this stuff to work? Or am I fundamentally misunderstanding something about the way entity beans are created?

      I apologize if this question has been posted before but I can't seem to search for phrases in these forums.

      Thanks,
      Emery
      ewl@genscape.com

      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      javax.transaction.TransactionRolledbackException: id may not be null; nested exception is:
      java.lang.Error: id may not be null
      javax.transaction.TransactionRolledbackException: id may not be null; nested exception is:
      java.lang.Error: id may not be null
      java.lang.Error: id may not be null
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invokeHome(Unknown Source)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:258)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
      at $Proxy0.create(Unknown Source)
      at com.genscape.beans.Test.main(Test.java:154)


      calling plantHome.create(6342)...
      javax.ejb.CreateException: Could not create entity:java.sql.SQLException: General error: Column 'plant_name' cannot be null
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invokeHome(Unknown Source)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:258)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
      at $Proxy0.create(Unknown Source)
      at com.genscape.beans.Test.main(Test.java:154)

        • 1. Re: java.lang.Error: id may not be null / Column 'plant_id'
          daftarie

          Hi,
          we have the same problem with JBoss 3.0 beta / RC1 / RC2.
          ("column 'id' cannot be null" when creating a CMP 2.0 Entity Bean. The column is set but the MySQL driver returns this error when trying to insert the row.
          The entity beans are generated via middlegen.

          Could it be that there's an error in a deployment descriptor?

          That's the stacktrace:
          08:59:36,058 ERROR [Lizenzmodell] Could not create entity
          java.sql.SQLException: General error: Column 'lizenzModell' cannot be null
          at org.gjt.mm.mysql.MysqlIO.sendCommand(Unknown Source)
          at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Unknown Source)
          at org.gjt.mm.mysql.Connection.execSQL(Unknown Source)
          at org.gjt.mm.mysql.PreparedStatement.executeUpdate(Unknown Source)
          at org.gjt.mm.mysql.PreparedStatement.executeUpdate(Unknown Source)
          at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.executeU
          pdate(LocalPreparedStatement.java:308)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(J
          DBCCreateEntityCommand.java:196)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCr
          eateEntityCommand.java:131)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStor
          eManager.java:444)
          at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersisten
          ceManager.java:253)
          at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.crea
          teEntity(CachedConnectionInterceptor.java:231)
          at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:57
          9)
          at java.lang.reflect.Method.invoke(Native Method)
          at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityC
          ontainer.java:1116)
          at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
          tor.java:73)
          at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(Ent
          itySynchronizationInterceptor.java:230)
          at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
          keHome(CachedConnectionInterceptor.java:176)
          at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInst
          anceInterceptor.java:134)
          at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInte
          rceptor.java:79)
          at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCrea
          tionInterceptor.java:44)
          at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
          rceptor.java:98)
          at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
          torCMT.java:167)
          at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
          va:52)
          at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
          tor.java:104)
          at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
          09)
          at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
          at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(Base
          LocalContainerInvoker.java:227)
          at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java
          :110)
          at $Proxy29.create(Unknown Source)
          at de.fhg.iao.komponentenrepository.ejb.session.impl.EinstellenBean.eins
          tellen(Unknown Source)
          at java.lang.reflect.Method.invoke(Native Method)
          at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
          tatelessSessionContainer.java:664)
          at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
          ke(CachedConnectionInterceptor.java:147)
          at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
          elessSessionInstanceInterceptor.java:77)
          at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
          rceptor.java:96)
          at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
          torCMT.java:167)
          at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
          1)
          at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
          java:129)
          at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
          at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContai
          ner.java:313)
          at org.jboss.ejb.Container.invoke(Container.java:706)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
          at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
          at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.jav
          a:102)
          at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.
          java:73)
          at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:7
          6)
          at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessi
          onInterceptor.java:111)
          at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
          at $Proxy38.einstellen(Unknown Source)
          at de.fhg.iao.komponentenrepository.client.struts.einstellen.MetadatenBe
          staetigungAction.komponenteEinstellen(MetadatenBestaetigungAction.java:169)
          at de.fhg.iao.komponentenrepository.client.struts.einstellen.MetadatenBe
          staetigungAction.perform(MetadatenBestaetigungAction.java:61)
          at org.apache.struts.action.ActionServlet.processActionPerform(ActionSer
          vlet.java:1787)
          at org.apache.struts.action.ActionServlet.process(ActionServlet.java:158
          6)
          at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
          icationFilterChain.java:247)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
          ilterChain.java:193)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
          alve.java:243)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:566)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
          a:472)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
          alve.java:190)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:566)
          at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve
          .java:246)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:564)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
          a:472)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

          at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
          2343)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
          ava:180)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:566)
          at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
          rValve.java:170)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:564)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
          ava:170)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:564)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
          468)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:564)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
          a:472)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
          ve.java:174)
          at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
          .java:566)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
          a:472)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

          at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcesso
          r.java:1012)
          at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.ja
          va:1107)
          at java.lang.Thread.run(Thread.java:484)
          08:59:36,159 INFO [STDOUT] Could not create entity:java.sql.SQLException: Gener
          al error: Column 'lizenzModell' cannot be null

          Here's the entry in ejb-jar.xml:
          ...

          <![CDATA[No Description.]]>

          <ejb-name>Lizenzmodell</ejb-name>

          <local-home>de.fhg.iao.komponentenrepository.ejb.entity.interfaces.LizenzmodellLocalHome</local-home>
          de.fhg.iao.komponentenrepository.ejb.entity.interfaces.LizenzmodellLocal

          <ejb-class>de.fhg.iao.komponentenrepository.ejb.entity.impl.LizenzmodellCMP</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>de.fhg.iao.komponentenrepository.ejb.entity.interfaces.LizenzmodellPK</prim-key-class>
          False
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>Lizenzmodell</abstract-schema-name>
          <cmp-field>
          <![CDATA[Returns the lizenzModell]]>
          <field-name>lizenzModell</field-name>
          </cmp-field>


          <query-method>
          <method-name>findAll</method-name>
          <method-params/>
          </query-method>
          <ejb-ql>
          <![CDATA[SELECT OBJECT(a) FROM Lizenzmodell AS a WHERE a.lizenzModell IS NOT NULL]]>
          </ejb-ql>



          ...

          Thanks for your help.

          • 2. Re: java.lang.Error: id may not be null / Column 'plant_id'
            dsundstrom

            Did you give every pk field a value in ejbCreate? If not you need to.

            • 3. Re: java.lang.Error: id may not be null / Column 'plant_id'
              casanova

              Had the same problem with MySQL - it seems to be due to the lack of transaction support in MySQL combined with attempting to use autonumbering for the primary key. If you're doing something completely different then I might be completely off the track! But it sounds to be the same. I found that the following worked for me. Basically you need to manually do the transaction stuff rather than letting JBoss automate it:

              public UserKey ejbCreate(java.lang.String firstName, java.lang.String lastName) throws CreateException
              {
              Context ctx;
              UserHome home;
              Vector vec;
              int max = 0;
              int current = 0;
              try
              {
              ctx = new InitialContext(System.getProperties());
              home = (UserHome) ctx.lookup("User");
              vec = new Vector(home.findAll());
              for(int i=0; i<vec.size(); i++)
              {
              current = ((User)vec.elementAt(i)).getUserId();
              if(current > max)
              {
              max = current;
              }
              }
              this.setUserId(max + 1);
              }
              catch (javax.naming.NamingException ne)
              {
              ne.printStackTrace();
              }
              catch(java.rmi.RemoteException re)
              {
              re.printStackTrace();
              }
              catch(javax.ejb.FinderException fe)
              {
              fe.printStackTrace();
              }
              this.adminRights = "false";
              this.staffRights = "false";
              this.clientRights = "false";
              this.city = "";
              this.email = "";
              this.setLogonFailNum(0);
              this.firstName = firstName;
              this.lastName = lastName;
              this.password = "";
              this.postcode = "";
              this.street = "";
              this.telephone = "";
              this.userName = userName;
              this.userLocked = "false";
              return null;
              }

              Hope this helps.