2 Replies Latest reply on Mar 12, 2002 3:29 PM by Andi Germeroth

    Newbie : Jboss 2.4.3 , CMP: ejbCreate throws NullPointerExce

    Andi Germeroth Newbie

      Hello all,

      I am evaluating if we use JBoss and CMP for our next project.
      I setup Jboss 2.4 with Postgres and ran the CDBean - CMP - sample, it worked fine.
      To get in touch with all this J2EE stuff and CMP, I wrote a small test application
      which is similar to the Jboss CMP samples.
      I have got a entity bean (UserBean), a serializable value object (UserValue) and a stateless
      session bean (UserSession) for clients. I use the JBossUtilAutoNumber to autoincrement the userId.
      The two tables are created in the database.
      In the attached code, the addUser() method should insert a new User in the database.
      My problem is, that the ejbCreate() - method of the bean throws a NullPointerException.
      To get more info about this error I turned on debugging for jaws.

      Whats wrong ??

      Thanks for your help.



      ejb-jar.xml :
      ------------------------
      <ejb-jar>
      <display-name>Bionicon Order System</display-name>
      <enterprise-beans>
      <!-- Auto Increment Util -->

      <ejb-name>JBossUtilAutoNumber</ejb-name>
      org.jboss.util.AutoNumberHome
      org.jboss.util.AutoNumber
      <ejb-class>org.jboss.util.AutoNumberEJB</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      True
      <cmp-field><field-name>name</field-name></cmp-field>
      <cmp-field><field-name>value</field-name></cmp-field>
      <primkey-field>name</primkey-field>



      Models a User
      <ejb-name>UserBean</ejb-name>
      siteos.bionicon.user.interfaces.UserHome
      siteos.bionicon.user.interfaces.User
      <ejb-class>siteos.bionicon.user.bean.UserBean</ejb-class>
      <!-- Container Managed Persistence -->
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-field><field-name>userId</field-name></cmp-field>
      <cmp-field><field-name>login</field-name></cmp-field>
      <cmp-field><field-name>password</field-name></cmp-field>
      <primkey-field>userId</primkey-field>



      Models use cases for Users
      <ejb-name>UserSessionBean</ejb-name>
      siteos.bionicon.user.interfaces.UserSessionHome
      siteos.bionicon.user.interfaces.UserSession
      <ejb-class>siteos.bionicon.user.bean.UserSessionBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <ejb-ref>
      <ejb-ref-name>ejb/User</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      siteos.bionicon.user.interfaces.UserHome
      siteos.bionicon.user.interfaces.User
      <ejb-link>UserBean</ejb-link>
      </ejb-ref>



      </enterprise-beans>

      <assembly-descriptor>
      <container-transaction>

      <ejb-name>UserBean</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>
      --------------------

      UserBean.java:
      --------------------
      public class UserBean implements EntityBean
      {
      public Integer userId;
      private String login;
      private String password;

      EntityContext ctx;


      /**
      *
      */
      public Integer ejbCreate ()
      {
      userId = AutoNumberFactory.getNextInteger("UserBean");
      System.out.println("ejBCreate Called " + userId);
      return null;
      }

      public void ejbPostCreate() { }


      public void setEntityContext(EntityContext ctx) { this.ctx = ctx; }

      public void unsetEntityContext() { ctx = null; }

      public void ejbActivate() { }
      public void ejbPassivate() { }
      public void ejbLoad() { }
      public void ejbStore() { }
      public void ejbRemove() { }

      public void setValueObject(UserValue value)
      {
      userId = value.getUserId();
      login = value.getLogin();
      password = value.getPassword();
      }

      public UserValue getValueObject()
      {
      UserValue value = new UserValue();
      value.setUserId(userId);
      value.setLogin(login);
      value.setPassword(password);
      return value;
      }


      }
      -------------------------

      UserSession.java :
      -------------------------
      ...

      public void addUser(UserValue value) throws RemoteException
      {
      //get home interface
      UserHome home = (UserHome) getHome("user/User", UserHome.class);
      try
      {
      //here happens the Exception
      User user = home.create();
      //set Value
      user.setValueObject(value);
      }
      catch (Exception e2)
      {
      throw new EJBException (e2);
      }
      }
      ...
      --------------------------

      The Exception , wow !
      --------------------------
      [Default] ejBCreate Called 0
      [JAWS] Create, id is 0
      [JAWS] Exists command executing: SELECT COUNT(*) FROM UserBean WHERE userId=?
      [JAWS] Set parameter: idx=1, jdbcType=INTEGER, value=0
      [JAWS] Create command executing: INSERT INTO UserBean (password,login,userId) VALUES (?,?,?)
      [JAWS] java.lang.NullPointerException
      [JAWS] at org.jboss.ejb.plugins.jaws.metadata.CMPFieldMetaData.getValue(CMPFieldMetaData.java:363)
      [JAWS] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.getCMPFieldValue(JDBCCommand.java:640)
      [JAWS] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCreateEntityCommand.setParameters(JDBCCreateEntityComman
      d.java:163)
      [JAWS] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecute(JDBCCommand.java:159)
      [JAWS] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java
      :135)
      [JAWS] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.createEntity(JAWSPersistenceManager.java:1
      28)
      [JAWS] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:231)
      [JAWS] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:616)
      [JAWS] at java.lang.reflect.Method.invoke(Native Method)
      [JAWS] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:843)
      [JAWS] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInter
      ceptor.java:231)
      [JAWS] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:15
      4)
      [JAWS] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:108)
      [JAWS] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:135)
      [JAWS] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:307)
      [JAWS] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
      [JAWS] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:103)
      [JAWS] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:106)
      [JAWS] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:420)
      [JAWS] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerInvoker.java:
      441)
      [JAWS] at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:237)
      [JAWS] at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
      [JAWS] at $Proxy25.create(Unknown Source)
      [JAWS] at siteos.bionicon.order.bean.OrderSessionBean.addUser(OrderSessionBean.java:70)
      [JAWS] at java.lang.reflect.Method.invoke(Native Method)
      [JAWS] at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulSessionContainer.
      java:650)
      [JAWS] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:128)
      [JAWS] at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInter
      ceptor.java:243)
      [JAWS] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
      [JAWS] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:307)
      [JAWS] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
      [JAWS] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
      [JAWS] at org.jboss.ejb.StatefulSessionContainer.invoke(StatefulSessionContainer.java:341)
      [JAWS] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:395)
      [JAWS] at java.lang.reflect.Method.invoke(Native Method)
      [JAWS] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:242)
      [JAWS] at sun.rmi.transport.Transport$1.run(Transport.java:155)
      [JAWS] at java.security.AccessController.doPrivileged(Native Method)
      [JAWS] at sun.rmi.transport.Transport.serviceCall(Transport.java:152)
      [JAWS] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:462)
      [JAWS] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:662)
      [JAWS] at java.lang.Thread.run(Thread.java:498)
      [EntitySynchronizationInterceptor] beforeCompletion called for ctx org.jboss.ejb.EntityEnterpriseContex
      t@2e3bd49b
      [EntitySynchronizationInterceptor] Checking ctx=org.jboss.ejb.EntityEnterpriseContext@2e3bd49b, for sta
      tus of tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=Gandalf//3, BranchQual=]
      [EntitySynchronizationInterceptor] afterCompletion, clear tx for ctx=org.jboss.ejb.EntityEnterpriseCont
      ext@2e3bd49b, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=Gandalf//3, BranchQual=]
      [EntitySynchronizationInterceptor] afterCompletion, sent notify on TxLock for ctx=org.jboss.ejb.EntityE
      nterpriseContext@2e3bd49b
      [UserSessionBean] TRANSACTION ROLLBACK EXCEPTION:null
      Embedded Exception
      Could not create entity:java.lang.NullPointerException; nested exception is:
      javax.ejb.EJBException: null
      Embedded Exception
      Could not create entity:java.lang.NullPointerException
      [UserSessionBean] javax.ejb.CreateException: Could not create entity:java.lang.NullPointerException
      [UserSessionBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEn
      tityCommand.java:139)
      [UserSessionBean] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.createEntity(JAWSPersisten
      ceManager.java:128)
      [UserSessionBean] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManag
      er.java:231)
      [UserSessionBean] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:616)
      [UserSessionBean] at java.lang.reflect.Method.invoke(Native Method)
      ....