0 Replies Latest reply on Jan 28, 2004 4:52 AM by arweb

    Could not create entity - Column 'userident' cannot be null

    arweb Newbie

       

      "arweb" wrote:
      I am using JBoss 3.2.1 with MySQL 3.2.3 and i am not able to create an Entity bean (CMP) with a primary key class. The PK class just contains a single attribute which explicitly is set to a value != null. Even if i use the java.lang.String attribute directly as primary key without using PK class i get the same error. I am frustrated and hope anyone can show me a way to prevent this problem. Here the java/descriptor code in detail:

      EXCEPTION:

      11:26:31,180 ERROR [UserEntityBean] Could not create entity
      java.sql.SQLException: General error, message from server: "Column 'userident' cannot be null
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1876)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1098)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1192)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:2051)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1680)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1527)
      at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedP
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(JDBCCreateE
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntity
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.j
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(C
      at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:725)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.j
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:8
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchro
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(Cac
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:8
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterc
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.ja
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterc
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.ja
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.jav
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:9
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFind
      at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:477)
      at org.jboss.ejb.Container.invoke(Container.java:694)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatche
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)


      Primary Key CLASS
      =============

      public class UserBeanPK implements java.io.Serializable
      {

      public String userId = ""; // must be public

      public UserBeanPK() // default constructor is neccassary
      {
      }

      public UserBeanPK(String userId)
      {
      this.userId = userId;
      }

      public boolean equals(Object key)
      {
      return key instanceof UserBeanPK ? userId.equals(((UserBeanPK)key).userId) : false;
      }

      public int hashCode()
      {
      return userId.hashCode();
      }
      }


      ejb-jar.xml
      =========


      <entity>
      <display-name>UserEntityBean</display-name>
      <ejb-name>UserEntityBean</ejb-name>
      <home>de.riechert.j2eecore.ejb.entity.UserHome</home>
      <local-home>de.riechert.j2eecore.ejb.entity.UserHomeLocal</local-home>
      <remote>de.riechert.j2eecore.ejb.entity.UserEntity</remote>
      <local>de.riechert.j2eecore.ejb.entity.UserEntityLocal</local>
      <ejb-class>de.riechert.j2eecore.ejb.entity.UserEntityBean</ejb-class>
      <persistence-type>Container</persistence-type>

      <prim-key-class>de.riechert.j2eecore.ejb.entity.UserBeanPK</prim-key-class>
      <!--
      <prim-key-class>java.lang.String</prim-key-class>
      <primkey-field>userId</primkey-field>
      -->

      <reentrant>False</reentrant>
      <transaction-type>Container</transaction-type>
      <cmp-version>2.x</cmp-version>

      <abstract-schema-name>UserEntity</abstract-schema-name>

      <cmp-field><field-name>id</field-name></cmp-field>
      <cmp-field><field-name>serialNumber</field-name></cmp-field>
      <cmp-field><field-name>lastUpdate</field-name></cmp-field>
      <cmp-field><field-name>modified</field-name></cmp-field>

      <cmp-field><field-name>userId</field-name></cmp-field>
      <cmp-field><field-name>userName</field-name></cmp-field>
      <cmp-field><field-name>password</field-name></cmp-field>
      <cmp-field><field-name>groups</field-name></cmp-field>
      <cmp-field><field-name>phone</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>
      <cmp-field><field-name>roles</field-name></cmp-field>
      <cmp-field><field-name>validFrom</field-name></cmp-field>
      <cmp-field><field-name>validTo</field-name></cmp-field>

      <query>
      <query-method>
      <method-name>findAll</method-name>
      <method-params></method-params>
      </query-method>
      <ejb-ql>SELECT OBJECT(c) FROM UserEntity AS c</ejb-ql>
      </query>

      <query>
      <query-method>
      <method-name>findByUserId</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>SELECT OBJECT(c) from UserEntity c WHERE c.userId = ?1</ejb-ql>
      </query>

      </entity>


      jbosscmp-jdbc.xml
      ===================


      <jbosscmp-jdbc>


      <defaults>
      <datasource>java:/j2eeDS</datasource>
      <datasource-mapping>mySQL</datasource-mapping>
      <create-table>true</create-table>
      <remove-table>false</remove-table>
      <pk-constraint>false</pk-constraint>
      </defaults>

      <enterprise-beans>
      <entity>
      <ejb-name>UserEntityBean</ejb-name>
      <table-name>user</table-name>

      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>INTEGER</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>serialNumber</field-name>
      <column-name>serialnumber</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastUpdate</field-name>
      <column-name>lastupdate</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>modified</field-name>
      <column-name>modified</column-name>
      </cmp-field>

      <cmp-field>
      <field-name>userId</field-name>
      <column-name>userident</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(16)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>userName</field-name>
      <column-name>username</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      <column-name>password</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>phone</field-name>
      <column-name>phone</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>email</field-name>
      <column-name>email</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>groups</field-name>
      <column-name>groups</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>roles</field-name>
      <column-name>roles</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>validFrom</field-name>
      <column-name>validFrom</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>validTo</field-name>
      <column-name>validTo</column-name>
      </cmp-field>

      </entity>
      </enterprise-beans>

      </jbosscmp-jdbc>

      The ejbCreate() method
      ======================


      public UserBeanPK ejbCreate(String userId) throws CreateException
      // public String ejbCreate(String userId) throws CreateException
      {
      System.out.println("EJB_CREATE------>" + userId);
      this.userId = userId;
      return null; // CMP --> return null, BMP -->return PK object reference
      }


      The client call
      ==================

      UserHome userHome = (UserHome)acc.getRemoteHome(UserHome class);
      System.out.println("UserHome looked up !!");
      UserEntity userBean = userHome.create("MyName");

      ********** FAILES !!!!!!!!!!!!!!! *****************