0 Replies Latest reply on Jan 27, 2003 10:11 AM by bongosdude

    NullPointerException with Oracle datasource

    bongosdude

      I just installed jboss-3.0.4_tomcat-4.1.12 and tried to see if I could deploy the entity bean with an ORACLE datasource.
      I used the template ant build to compile and build my entity bean. Xdoclet created all xml deployment files. The deployment was
      successful and created the table. But when the client program tries to get the entity home and invokes any home method ejbFindXXXX or ejbSelectXXXX method, I got
      a NullPointerException. Here is my enviroment information:

      jboss-3.0.4_tomcat-4.1.12
      Windows 2000 server
      JDK 1.3.1_03 (build 1.3.1_03-b03)
      Oracle JDBC thin driver: 9.2.0.1




      10:10:37,351 ERROR [LogInterceptor] EJBException, causedBy:
      java.lang.NullPointerException
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityEJBLocalObject(BaseLocalContainerInvoker.java:199)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityLocalCollection(BaseLocalContainerInvoker.java:210)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.execute(JDBCAbstractQueryCommand.java:174)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCSelectorBridge.execute(JDBCSelectorBridge.java:64)
      at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:96)
      at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
      at com.ecentives.em.data.code.CodeEJBCMP$Proxy.ejbSelectAllCodeBeans()
      at com.ecentives.em.data.code.CodeEJBBean.ejbHomeGetCodesData(CodeEJBBean.java:379)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1138)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:206)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:90)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:44)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:111)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:105)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:129)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
      at org.jboss.ejb.Container.invoke(Container.java:730)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1058)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:382)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:236)
      at sun.rmi.transport.Transport$1.run(Transport.java:147)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:143)
      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:479)


      ///////////////////// This is my bean //////////////////////////////////////////


      package com.ecentives.em.data.code;

      import com.ecentives.em.data.info.*;

      import java.rmi.RemoteException;
      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Iterator;
      import javax.ejb.CreateException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.FinderException;
      import javax.ejb.RemoveException;


      /**
      * *********************** JavaDoc *********************************************
      * This bean is a container-managed Entity Bean. It contains the implementation of the Code Bean
      * @author OSE-DEV, Copyright (c) 2001 by e-centives, Inc. All Rights Reserved.
      * @version $Id: $
      * *********************** Ejb Doclet*******************************************
      * @ejb:bean
      * name="com/ecentives/em/data/code/CodeEJB"
      * display-name="OSE Code"
      * view-type="remote"
      * jndi-name="CodeEJBHome"
      * type="CMP"
      * cmp-version="2.x"
      * schema="CodeEJBBean"
      * @ejb:home
      * generate="remote"
      * remote-class="com.ecentives.em.data.code.CodeEJBHome"
      *
      * @ejb:interface
      * generate="remote"
      * remote-class="com.ecentives.em.data.code.CodeEJB"
      *
      * @ejb:transaction type="Required"
      * @ejb:data-object extends="com.ecentives.em.IF.AbstractData"
      * setdata="true"
      * package="com.ecentives.em.data.info"
      *
      * @ejb:finder signature="java.util.Collection findByCodeType(java.lang.String theType)"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a WHERE a.codeType = ?1"
      *
      * @ejb:finder signature="com.ecentives.em.data.code.CodeEJB findByCodeTypeAndValue(java.lang.String theType,java.lang.String theVal)"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a WHERE a.codeType = ?1 AND a.codeValue = ?2"
      *
      * @ejb:finder signature="com.ecentives.em.data.code.CodeEJB findOriginalContainerCode()"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a WHERE a.codeType = 'CONTAINER_TYPE' AND a.codeValue = 'ORIGINAL'"
      *
      * @ejb:finder signature="com.ecentives.em.data.code.CodeEJB findTrialCampaignTypeCode()"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a WHERE a.codeType = 'CAMPAIGN_TYPE' AND a.codeValue = 'TRIAL'"
      *
      * @ejb:finder signature="com.ecentives.em.data.code.CodeEJB findProductionCampaignTypeCode()"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a WHERE a.codeType = 'CAMPAIGN_TYPE' AND a.codeValue = 'PRODUCTION'"
      *
      * @ejb:finder signature="java.util.Collection findAllCodeBeans()"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a"
      *
      * @ejb:select signature="java.util.Collection ejbSelectAllCodeBeans()"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a"
      *
      * @ejb:select signature="java.util.Collection ejbSelectContainerTypeCodes()"
      * query="SELECT OBJECT(a) FROM CodeEJBBean a WHERE a.codeType = 'CONTAINER_TYPE'"
      *
      * @jboss:table-name table-name="MYCODES"
      * @jboss:remove-table remove="false"
      * @jboss:create-table create="true"
      * @jboss:read-only:"true"
      *
      *
      *
      **/



      abstract public class CodeEJBBean implements EntityBean
      {
      /**
      * Entity context.
      */
      private EntityContext ctx;

      /**
      * Default constructor.
      */
      public CodeEJBBean()
      {
      super();
      };

      /**
      * Sets the entity context for the bean.
      *
      * @param ctx EntityContext
      * @return None
      */
      public void setEntityContext(EntityContext ctx)
      {
      this.ctx = ctx;
      }

      /**
      * Unsets the entity context for the bean.
      *
      * @return None
      */
      public void unsetEntityContext()
      {
      this.ctx = null;
      }

      /**
      * Retrieve code id.
      *
      * @return Returns an int representing the id of this Code.
      *
      * @ejb:persistent-field
      * @ejb:pk-field
      * @jboss:column-name "CODE_ID"
      */
      abstract public int getCodeId();

      /**
      * Sets the code ID.
      *
      * @param codeId Code ID
      * @return None
      */
      abstract public void setCodeId(int codeId);

      /**
      * Gets the code value.
      *
      * @return Code value
      *
      * @ejb:persistent-field
      * @jboss:column-name "CODE_VALUE"

      */
      abstract public String getCodeValue();

      /**
      * Sets the code value.
      *
      * @param codeValue Code value
      * @return None
      */
      abstract public void setCodeValue(String codeValue);

      /**
      * Gets the code description.
      *
      * @return Code description
      *
      * @ejb:persistent-field
      * @jboss:column-name "CODE_DESCR"
      */
      abstract public String getCodeDescription();

      /**
      * Sets the code description.
      *
      * @param codeDescription Code description
      * @return None
      */
      abstract public void setCodeDescription(String codeDescription);

      /**
      * Gets the code type.
      *
      * @return Code type
      *
      * @ejb:persistent-field
      *
      * @jboss:column-name "CODE_TYPE"
      *
      */
      abstract public String getCodeType();

      /**
      * Sets the code type.
      *
      * @param codeType Code type
      * @return None
      */
      abstract public void setCodeType(String codeType);

      /**
      * Selects all Code Beans. This is a select method implemented
      * by the container.
      *
      * @return Collection of Code Beans
      */
      abstract public Collection ejbSelectAllCodeBeans()
      throws FinderException;

      /**
      * Selects all container type Code Beans. This is a select method implemented
      * by the container.
      *
      * @return Collection of Code Beans
      */
      abstract public Collection ejbSelectContainerTypeCodes()
      throws FinderException;

      /**
      * This method corresponds to the create method in the home interface. The
      * parameter sets of the two methods are identical. When the client calls
      * CodeEJBHome.create(), the container (which in WebLogic EJB is
      * also the factory) allocates an instance of this bean and calls
      * CodeEJBBean.ejbCreate().
      *
      * For container-managed persistence, ejbCreate() returns a null,
      * unlike the case of bean-managed persistence, where it returns a primary key.
      *
      * @param codeId Code ID
      * @param codeValue Code value
      * @param codeDescription Code description
      * @param codeType Code type.
      * @return Primary key
      * @exception javax.ejb.CreateException if there is an error
      * creating the bean
      *
      * @ejb:create-method view-type="remote"
      *
      */


      public CodeEJBPK ejbCreate(int codeId, String codeValue, String codeDescription,
      String codeType)
      throws CreateException
      {

      //
      // Set attributes.
      //
      setCodeId(codeId);
      setCodeValue(codeValue);
      setCodeDescription(codeDescription);
      setCodeType(codeType);

      return null;
      }

      /**
      * This method is required by the EJB Specification, but is not used here.
      *
      * @param codeId Code ID
      * @param codeValue Code value
      * @param codeDescription Code description
      * @param codeType Code type.
      * @return None
      */
      public void ejbPostCreate(int codeId, String codeValue, String codeDescription,
      String codeType)
      {
      }

      /**
      * This method is required by the EJB Specification, but is not used here.
      *
      * @return None
      * @exception javax.ejb.RemoveException if the bean cannot be
      * removed.
      */
      public void ejbRemove()
      throws RemoveException
      {
      }

      /**
      * This method is required by the EJB Specification, but is not used here.
      *
      * @return None
      */
      public void ejbActivate()
      {
      }

      /**
      * This method is required by the EJB Specification, but is not used here.
      *
      * @return None
      */
      public void ejbPassivate()
      {
      }

      /**
      * This method is required by the EJB Specification, but is not used here.
      *
      * @return None
      */
      public void ejbLoad()
      {
      }

      /**
      * This method is required by the EJB Specification, but is not used here.
      *
      * @return None
      */
      public void ejbStore()
      {
      }

      /**
      * Gets the data for all the codes. When the client calls
      * CodeEJBHome.getCodesData(), the container calls
      * CodeEJBBean.ejbHomeGetCodesData().
      *
      * @ejb:home-method view-type="remote"
      *
      * @return Data for all codes.
      * @exception javax.ejb.FinderException if there is an error
      * finding the beans
      */
      public ArrayList ejbHomeGetCodesData()
      throws FinderException
      {

      //
      // Initialize.
      //
      System.out.println("Enter ejbHomeGetCodesData");
      ArrayList codesData = new ArrayList();

      //
      // Call the select method to get all the Code Beans.
      //
      Collection col = null;
      try
      {
      col = ejbSelectAllCodeBeans();
      System.out.println("a ejbSelectAllCodeBeans");

      }
      catch (FinderException e1)
      {
      System.out.println("Error 1: " + e1.getMessage());
      throw e1;
      }

      Iterator itr = col.iterator();

      while (itr.hasNext())
      {
      CodeEJB codeBean = (CodeEJB) itr.next();
      System.out.println("loop: b get data");

      //
      // Get the data in the bean and add to list.
      //
      // CodeInfo codeData = codeBean.getData();
      try
      {
      CodeEJBData codeData = codeBean.getData();
      codesData.add(codeData);
      System.out.println("loop: a get data");

      }
      catch (Exception e)
      {
      throw new FinderException(e.getMessage() );
      }


      }

      //
      // Compact the list and return data for all codes.
      //
      codesData.trimToSize();
      System.out.println("Exit ejbHomeGetCodesData");

      return codesData;
      }


      /**
      * Returns the Primary Key identifying this bean.
      *
      * @return String identification
      */
      private String id()
      {
      return (String) ((ctx == null) ? "null context" :
      ((ctx.getPrimaryKey() == null ? "null primary key" :
      ctx.getPrimaryKey().toString())));
      }

      /**
      * Gets the data for all the Container type codes. When the client calls
      * CodeEJBHome.getContainerTypeCodesData(), the container calls
      * CodeEJBBean.ejbHomeGetContainerTypeCodesData().
      *
      * @ejb:home-method view-type="remote"
      *
      * @return Data for all codes.
      * @exception javax.ejb.FinderException if there is an error
      * finding the beans
      * @exception java.rmi.RemoteException if there is a
      * communications or systems failure
      */
      public ContainerTypeCodeInfo ejbHomeGetContainerTypeCodesData()
      throws FinderException
      {

      //
      // Initialize.
      //
      ArrayList codesData = new ArrayList();

      //
      // Call the select method to get all the Code Beans.
      //
      Collection col = ejbSelectContainerTypeCodes();
      Iterator itr = col.iterator();
      while (itr.hasNext())
      {
      CodeEJB codeBean = (CodeEJB) itr.next();

      //
      // Get the data in the bean and add to list.
      //
      // CodeInfo codeData = codeBean.getData();

      try
      {
      CodeEJBData codeData = codeBean.getData();
      codesData.add(codeData);

      }
      catch (Exception e)
      {
      System.out.println("Get Error: " + e.getMessage());
      throw new FinderException(e.getMessage());
      }

      }

      //
      // Compact the list and return data for all codes.
      //
      codesData.trimToSize();
      return new ContainerTypeCodeInfo(codesData);
      }


      /**
      * Gets the data in the bean.
      *
      * @return Data in the Code Bean
      *
      * @ejb:interface-method view-type="remote"
      *
      */

      abstract public com.ecentives.em.data.info.CodeEJBData getData();

      }