OK, here is the code and deployment descriptor. I apologize that there is a 
lot here, but I have included one entity bean, a session bean that creates 
this entity bean, and the deployment descriptor.

Eventually I am planning to move all the address information into a 
dependant object, but heck, I have to get create working first ;-)

Thanks VERY much!

Jim


// CrHome.java

package com.regtek.eb20;

import java.rmi.RemoteException;
import java.util.*;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
import javax.ejb.FinderException;

import com.regtek.types.RegnetCR;
import com.regtek.types.RegnetTag;

public interface CrHome extends EJBHome {
    Cr create()
       throws CreateException, RemoteException;

    Cr create(RegnetCR cr)
       throws CreateException, RemoteException;

    Cr findByPrimaryKey(RegnetTag primaryKey)
       throws FinderException, RemoteException;

    Collection findByLastname(String lastname)
       throws FinderException, RemoteException;

    Collection findByFullName(String lastname, String firstname)
       throws FinderException, RemoteException;

    Collection findByEmail(String email)
       throws FinderException, RemoteException;

    Collection findByPhone(String phone)
       throws FinderException, RemoteException;

    Collection findAll()
       throws FinderException, RemoteException;
}


//-------------------------------------------------------------------------
-------

// CrEJB.java
// Cr EJB 2.0 Entity Bean

package com.regtek.eb20;

import java.rmi.RemoteException;

import java.sql.*;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Date;

import javax.ejb.*;
import javax.naming.*;
import javax.sql.DataSource;
import javax.transaction.*;

import com.regtek.types.RegnetCR;
import com.regtek.types.RegnetTag;

public abstract class CrEJB implements EntityBean {

    protected EntityContext ejbContext;
        
    public void setEntityContext(EntityContext ctx) {
      ejbContext = ctx;
    }

    public void unsetEntityContext() {
           ejbContext = null;
    }

    public void ejbRemove() throws RemoveException {
    }

    public void ejbLoad() {
    }

    public void ejbStore() {
    }
        
    public void ejbPostCreate() throws CreateException {
    }

//    public void ejbPostCreate(RegnetTag tag) throws CreateException {
//    }

    public void ejbPostCreate(RegnetCR cr) throws CreateException {
    }

    // ------------------------------------------------------------
    public RegnetTag ejbCreate() {
                trace("ejbCreate() entered");
                
                initToNull();
                
      trace("ejbCreate() entered");

      // In CMP, should return null.
      return null;
    }

    // ------------------------------------------------------------
    public RegnetTag ejbCreate(RegnetCR cr)
       throws CreateException {

                trace("ejbCreate(RegnetCR cr) entered");
                
                initToNull();
                
                if(cr == null)
                        return null;
        
      setTag(cr.getTag());

          setLastName(cr.getLastName());
          setFirstName(cr.getFirstName());
          setMiddleInitial(cr.getMiddleInitial());
        
      setAddr1(cr.getAddr1());
      setAddr2(cr.getAddr2());
      setAddr3(cr.getAddr3());
      setCity(cr.getCity());
      setState(cr.getState());
      setPostalCode(cr.getPostalCode());
      setCountryCode(cr.getCountryCode());
      setPhone(cr.getPhone());
      setFax(cr.getFax());
      setEmail(cr.getEmail());
        
          Date now = new Date();
        
          setDateAdded(now);
          setDateLastMod(now);

          trace("ejbCreate(RegnetCR cr) exiting");
        
        
      // In CMP, should return null.
      return null;
    }

    // ------------------------------------------------------------
    public void ejbPassivate() {}
    public void ejbActivate() {}

    // ------------------------------------------------------------
        private void initToNull()
        {
                trace("initToNull() entered");

                setTag(null);
                setFirstName(null);
                setLastName(null);
                setMiddleInitial(null);
                setAddr1(null);
                setAddr2(null);
                setAddr3(null);
                setCity(null);
                setState(null);
                setPostalCode(null);
                setCountryCode(null);
                setPhone(null);
                setFax(null);
                setEmail(null);
                setDateAdded(null);
                setDateLastMod(null);
                
                trace("initToNull() exiting");
        }

        // ---------------------------------------------------------    
        private void trace(String text)
        {
                java.util.Date now = new java.util.Date();
                System.out.println("EB CrEJB: " + now + " " + text);
        }


    // User Methods -------------------------------------------
    public abstract RegnetTag getTag();
    public abstract void setTag(RegnetTag tag);

    public abstract String getFirstName();
    public abstract void setFirstName(String fn);
        
        public abstract String getLastName();
    public abstract void setLastName(String ln);

    public abstract String getMiddleInitial();
    public abstract void setMiddleInitial(String mi);

        public abstract String getAddr1();
    public abstract void setAddr1(String addr1);

    public abstract String getAddr2();
    public abstract void setAddr2(String addr2);

    public abstract String getAddr3();
    public abstract void setAddr3(String addr3);

    public abstract String getCity();
    public abstract void setCity(String city);

    public abstract String getState();
    public abstract void setState(String state);

    public abstract String getPostalCode();
    public abstract void setPostalCode(String pc);

    public abstract String getCountryCode();
    public abstract void setCountryCode(String ctryCode);

    public abstract String getPhone();
    public abstract void setPhone(String phone);

    public abstract String getFax();
    public abstract void setFax(String fax);

    public abstract String getEmail();
    public abstract void setEmail(String email);
        
    public abstract Date getDateAdded();
    public abstract void setDateAdded(Date now);

    public abstract Date getDateLastMod();
    public abstract void setDateLastMod(Date lastMod);
 }


//--------------------------------------------------------------------------

// Cr.java

// This is the Cr EB remote interface - Its a CMP EJB v1.1 EJB

package com.regtek.eb20;

import java.rmi.RemoteException;
import javax.ejb.EJBObject;

import com.regtek.types.RegnetTag;

public interface Cr extends EJBObject {
    public RegnetTag getTag() throws RemoteException;
    public void setTag(RegnetTag tag) throws RemoteException;

    public String getLastName() throws RemoteException;
    public void setLastName(String ln) throws RemoteException;

    public String getFirstName() throws RemoteException;
    public void setFirstName(String fn) throws RemoteException;

    public String getMiddleInitial() throws RemoteException;
    public void setMiddleInitial(String mi) throws RemoteException;

    public String getAddr1() throws RemoteException;
    public void setAddr1(String addr1) throws RemoteException;

    public String getAddr2() throws RemoteException;
    public void setAddr2(String addr2) throws RemoteException;

    public String getAddr3() throws RemoteException;
    public void setAddr3(String addr3) throws RemoteException;

    public String getCity() throws RemoteException;
    public void setCity(String city) throws RemoteException;

    public String getState() throws RemoteException;
    public void setState(String state) throws RemoteException;

    public String getPostalCode() throws RemoteException;
    public void setPostalCode(String zip) throws RemoteException;

    public String getCountryCode() throws RemoteException;
    public void setCountryCode(String countryCode) throws RemoteException;

    public String getPhone() throws RemoteException;
    public void setPhone(String phone) throws RemoteException;

    public String getFax() throws RemoteException;
    public void setFax(String fax) throws RemoteException;

    public String getEmail() throws RemoteException;
    public void setEmail(String email) throws RemoteException;
}


// 
---------------------------------------------------------------------------
---------

// CreateNewCR.java

package com.regtek.slsb;

import java.rmi.RemoteException;

import com.regtek.types.RegnetCR;


public interface CreateNewCR extends javax.ejb.EJBObject
{
        public boolean makeNew(RegnetCR regCr) throws RemoteException;
}


//-------------------------------------------------------------------------

// CreateNewCRBean.java

package com.regtek.slsb;

import com.regtek.types.*;
// import com.regtek.eb_ejb_ver11.*;
import com.regtek.eb20.*;

import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;

import javax.ejb.*;
import javax.naming.*;

public class CreateNewCRBean implements javax.ejb.SessionBean
{
        public SessionContext context;
        private javax.naming.Context jndiContext = null;

        // ---------------------------------------------------------------
        public boolean makeNew(RegnetCR regCr) throws RemoteException
        {
                System.out.println("NewCRBean.makeNew() called");

                Context context = null;
                CrHome home = null;
                Cr cr = null;

                try
                {
                        System.out.println("NewCRBean.makeNew() - getting initial 
context");
                        context = new InitialContext();
                        
                        System.out.println("NewCRBean.makeNew() - lookup");
                        Object obj = context.lookup("java:comp/env/ejb/CrHomeEb");

                        System.out.println("NewCRBean.makeNew() - get the home 
object");
                        home = (CrHome) PortableRemoteObject.narrow(obj, CrHome.class);

                        System.out.println("NewCRBean.makeNew() - call create");
                        cr = home.create(regCr);
                }
                catch(RemoteException e)
                {
                        System.err.println("RE:System/communication error: " + 
e.getMessage());
                }
                catch(NamingException e)
                {
                        System.err.println("NE:Communication error: " + 
e.getMessage());
                }
                catch(CreateException e)
                {
                        System.err.println("CE:Error creating contact record: " + 
e.getMessage());
                }
                catch(ClassCastException e)
                {
                        System.err.println("CCE:Error narrowing object: " + 
e.getMessage());
                }

                
                return true;
        }


        // ---------------------------------------------------------------
        public void ejbCreate()
        {
        }
        
        // ---------------------------------------------------------------
        public void ejbActivate()
        {
        }
        
        // ---------------------------------------------------------------
        public void ejbPassivate()
        {
        }
        
        // ---------------------------------------------------------------
        public void ejbRemove()
        {
        }
        
        // ---------------------------------------------------------------
        public void setSessionContext(SessionContext ctx)
        {
                context = ctx;
                
                try
                {
                        jndiContext = new javax.naming.InitialContext();
                }
                catch(NamingException ne)
                {
                        throw new EJBException(ne);
                }
        }
}

//-------------------------------------------------------------------------
--------------

// CreateNewCRHome.java

package com.regtek.slsb;

import java.rmi.RemoteException;
import javax.ejb.CreateException;

public interface CreateNewCRHome extends javax.ejb.EJBHome
{
        public CreateNewCR create() throws RemoteException, CreateException;
}

//-------------------------------------------------------------------------
--

// RegnetTag.java

/*
        This class is a primary key class
*/

package com.regtek.types;

public class RegnetTag implements java.io.Serializable {
        public static final byte UNKNOWN = 0;
        public static final byte CR = 1;
        public static final byte DR = 2;
        public static final byte UAR = 3;
        public static final byte LIDR = 4;

        private int type;
        private String tagName;
        private String checkChar;


        // --------------------------------------------------------
        // Constructors
        // --------------------------------------------------------
        
        // This constructor creates a completely blank tag
        public RegnetTag()
        {
                setName("");
                setType(UNKNOWN);
                checkChar = null;
        }
                
        // --------------------------------------------------------
        // When passed a name and type, this constructor creates a
        // complete tag
        public RegnetTag(int type, String name)
        {
                setName(name);
                setType(type);
                
                caculateCheckChar();
        }
        
        // --------------------------------------------------------
        // This constructor will generate a unique tag of the
        // passed type
        public RegnetTag(int type)
        {
                setName("");
                setType(type);
                generate();
        }

        // --------------------------------------------------------
        // This constructor will take a full tag name and set this
        // RegnetTag to its values by parsing the passed string tag..
        public RegnetTag(String tagStr)
        {
                int one = tagStr.indexOf("-");
                int two = tagStr.lastIndexOf("-");
                int len = tagStr.length();
        
                String left = tagStr.substring(0, one);
                String middle = tagStr.substring(one, two);
                ++two; // Increment to land on the check char
                String right = tagStr.substring(two, len);
        
                setName(middle);

                type = UNKNOWN;
                
                if(left.equals("CR"))
                        type = CR;
                
                if(left.equals("DR"))
                        type = DR;
                
                if(left.equals("UAR"))
                        type = UAR;
                
                if(left.equals("LIDR"))
                        type = LIDR;
                
                String check = caculateCheckChar();
                if(!check.equals(right))
                        ; // Throw an invalid tag exception
                        
                // Done 
        }


        // --------------------------------------------------------
        // public methods
        // --------------------------------------------------------
        public void generate()
        {
                setName("GeneratedTag");
                caculateCheckChar();
        }

        
        // --------------------------------------------------------
        // private methods
        // --------------------------------------------------------
        private String caculateCheckChar()
        {
                checkChar = "X";
                return checkChar;
        }
        
        
        // --------------------------------------------------------
        // Public setters here
        // --------------------------------------------------------
                        
        public void setName(String name)
        {
                tagName = name;
                caculateCheckChar();
        }

        // --------------------------------------------------------
        public void setType(int type)
        {
                type = type;
                caculateCheckChar();
        }
        
        
        // --------------------------------------------------------
        // public getters here
        // --------------------------------------------------------

        public String getFullName()
        {
                String pre = "";
                
                if (type == CR)
                {
                        pre = "CR";
                }
        
                if (type == DR)
                {
                        pre = "DR";
                }

                if (type == UAR)
                {
                        pre = "UAR";
                }

                if (type == LIDR)
                {
                        pre = "LIDR";
                }

                return pre + "-" + tagName + "-" + checkChar;
        }

        // --------------------------------------------------------
        public String getName()
        {
                return tagName;
        }
        
        // --------------------------------------------------------
        public int getType()
        {
                return type;
        }
        
        // --------------------------------------------------------
        // These methods are required by the spec for any type to be
        // used as a primary key type
        // --------------------------------------------------------
        public int hashCode()
        {
                String str = getFullName();
                int hc = str.hashCode();
                
                return hc;
        }
        
        // --------------------------------------------------------
        public boolean equals(Object obj)
        {
                if(obj == null || !(obj instanceof RegnetTag))
                        return false;
                
                String me = this.getFullName();
                String it = ((RegnetTag) obj).getFullName();
                
                if(me.equals(it))
                    return true;
                        
                return false;   
        }
        
        // --------------------------------------------------------
        public String toString()
        {
                return this.getFullName();
        }       
        
}

//-------------------------------------------------------------------------
--



<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise 
JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
<ejb-jar>
        <description>RegNet</description>
        <display-name>RegNet</display-name>
        <enterprise-beans>
                <entity>
                        <description>RegNet CR - Contact Record</description>
                        <display-name>The com.regtek.eb20.Cr stateless session 
bean</display-name>
                        <ejb-name>com.regtek.eb20.Cr</ejb-name>
                        <home>com.regtek.eb20.CrHome</home>
                        <remote>com.regtek.eb20.Cr</remote>
                        <ejb-class>com.regtek.eb20.CrEJB</ejb-class>
                        <persistence-type>Container</persistence-type>
                        <prim-key-class>com.regtek.types.RegnetTag</prim-key-class>
                        <reentrant>False</reentrant>
                        
                        <cmp-field><field-name>tag</field-name></cmp-field>
                        <cmp-field><field-name>lastName</field-name></cmp-field>
                        <cmp-field><field-name>firstName</field-name></cmp-field>
                        <cmp-field><field-name>middleInitial</field-name></cmp-field>
                        <cmp-field><field-name>addr1</field-name></cmp-field>
                        <cmp-field><field-name>addr2</field-name></cmp-field>
                        <cmp-field><field-name>addr3</field-name></cmp-field>
                        <cmp-field><field-name>city</field-name></cmp-field>
                        <cmp-field><field-name>state</field-name></cmp-field>
                        <cmp-field><field-name>postalCode</field-name></cmp-field>
                        <cmp-field><field-name>countryCode</field-name></cmp-field>
                        <cmp-field><field-name>phone</field-name></cmp-field>
                        <cmp-field><field-name>fax</field-name></cmp-field>
                        <cmp-field><field-name>email</field-name></cmp-field>
                        <cmp-field><field-name>dateAdded</field-name></cmp-field>
                        <cmp-field><field-name>dateLastMod</field-name></cmp-field>

                        <primkey-field>tag</primkey-field>
                </entity>

                <entity>
                        <description>RegNet UAR - Contact Record</description>
                        <display-name>com.regtek.eb20.UarEJB</display-name>
                        <ejb-name>com.regtek.eb20.UarEJB</ejb-name>
                        <home>com.regtek.eb20.UarHome</home>
                        <remote>com.regtek.eb20.Uar</remote>
                        <ejb-class>com.regtek.eb20.UarEJB</ejb-class>
                        <persistence-type>Container</persistence-type>
                        <prim-key-class>com.regtek.types.RegnetTag</prim-key-class>
                        <reentrant>False</reentrant>

                        <cmp-field><field-name>tag</field-name></cmp-field>
                        <cmp-field><field-name>password</field-name></cmp-field>
                        <cmp-field><field-name>personal</field-name></cmp-field>
                        <cmp-field><field-name>endUser</field-name></cmp-field>
                        <cmp-field><field-name>entityName</field-name></cmp-field>
                        <cmp-field><field-name>addr1</field-name></cmp-field>
                        <cmp-field><field-name>addr2</field-name></cmp-field>
                        <cmp-field><field-name>addr3</field-name></cmp-field>
                        <cmp-field><field-name>city</field-name></cmp-field>
                        <cmp-field><field-name>state</field-name></cmp-field>
                        <cmp-field><field-name>postalCode</field-name></cmp-field>
                        <cmp-field><field-name>countryCode</field-name></cmp-field>
                        <cmp-field><field-name>phone</field-name></cmp-field>
                        <cmp-field><field-name>fax</field-name></cmp-field>
                        <cmp-field><field-name>crIsOwned</field-name></cmp-field>
      <cmp-field><field-name>cr</field-name></cmp-field>
            <ejb-ref>
              <ejb-ref-name>ejb/CrHomeEb</ejb-ref-name>
              <ejb-ref-type>Entity</ejb-ref-type>
              <home>com.regtek.eb20.CrHome</home>
              <remote>com.regtek.eb20.Cr</remote>
            </ejb-ref>
                        <primkey-field>tag</primkey-field>
                </entity>
                <session>
                        <description>Create a CR</description>
                        <display-name>com.regtek.slsb.CreateNewCR</display-name>
                        <ejb-name>com.regtek.slsb.CreateNewCR</ejb-name>
                        <home>com.regtek.slsb.CreateNewCRHome</home>
                        <remote>com.regtek.slsb.CreateNewCR</remote>
                        <ejb-class>com.regtek.slsb.CreateNewCRBean</ejb-class>
                        <session-type>Stateless</session-type>
                        <transaction-type>Container</transaction-type>
            <ejb-ref>
              <ejb-ref-name>ejb/CrHomeEb</ejb-ref-name>
              <ejb-ref-type>Entity</ejb-ref-type>
              <home>com.regtek.eb20.CrHome</home>
              <remote>com.regtek.eb20.Cr</remote>
            </ejb-ref>
                </session>
                
                <session>
                        <description>Create a UAR</description>
                        <display-name>com.regtek.slsb.CreateNewUAR</display-name>
                        <ejb-name>com.regtek.slsb.CreateNewUAR</ejb-name>
                        <home>com.regtek.slsb.CreateNewUARHome</home>
                        <remote>com.regtek.slsb.CreateNewUAR</remote>
                        <ejb-class>com.regtek.slsb.CreateNewUARBean</ejb-class>
                        <session-type>Stateless</session-type>
                        <transaction-type>Container</transaction-type>
            <ejb-ref>
              <ejb-ref-name>ejb/UarHomeEb</ejb-ref-name>
              <ejb-ref-type>Entity</ejb-ref-type>
              <home>com.regtek.eb20.UarHome</home>
              <remote>com.regtek.eb20.Uar</remote>
            </ejb-ref>
            <ejb-ref>
              <ejb-ref-name>ejb/CrHomeEb</ejb-ref-name>
              <ejb-ref-type>Entity</ejb-ref-type>
              <home>com.regtek.eb20.CrHome</home>
              <remote>com.regtek.eb20.Cr</remote>
            </ejb-ref>
                </session>
        </enterprise-beans>
        <relationships>
    <ejb-relation>
                        <ejb-relation-name>UAR-CR</ejb-relation-name>
                        <ejb-relationship-role>
                                <ejb-relationship-role-name>
                                        UAR-has-CR
                                </ejb-relationship-role-name>
                                <multiplicity>one</multiplicity>
                                <role-source>
                                        <ejb-name>com.regtek.eb20.UarEJB</ejb-name>
                                </role-source>
                                <cmr-field>
                                        <cmr-field-name>cr</cmr-field-name>
                                        
<cmr-field-type>com.regtek.eb20.CrEJB</cmr-field-type>
                                </cmr-field>
                        </ejb-relationship-role>
                        <ejb-relationship-role>
                                <ejb-relationship-role-name>
                                        CR-belongsto-UAR
                                </ejb-relationship-role-name>
                                <multiplicity>one</multiplicity>
                                <role-source>
                                        <ejb-name>com.regnet.eb20.UarEJB</ejb-name>
                                </role-source>
                        </ejb-relationship-role>
                </ejb-relation>

        </relationships>

   <assembly-descriptor>
      <security-role>
         <description>Users</description>
         <role-name>users</role-name>
      </security-role>
   </assembly-descriptor>
</ejb-jar>









--On Tuesday, October 17, 2000 11:32 AM -0700 Jeff Schnitzer 
<[EMAIL PROTECTED]> wrote:

> I have had no problems creating CMP entity beans from session beans with
> EJB2.0.  Seems to work as advertsied :-)
>
> I suggest posting your code and descriptors; I'll take a look, and the
> more examples of EJB2.0 beans floating around the better :-)
>
> Jeff
>
>> -----Original Message-----
>> From: Jim Archer [mailto:[EMAIL PROTECTED]]
>> Sent: Monday, October 16, 2000 4:18 PM
>> To: Orion-Interest
>> Subject: Please help! I get null pointer exception after
>> calling create
>> onan EB with EJB 2.0 CMP Orion 1.3.8...
>>
>>
>>
>> Hi All...
>>
>> Please help me out wityh this if you can. I'm really stuck
>> and already
>> behind schedual, so any ideas would be appreciated...
>>
>> I'm using Orion 1.3.8 and EJB 2.0 for CMP.
>>
>> I have written a fairley simple stateless session bean that's
>> job is to
>> just create a particular entity bean and populate it. This
>> session bean is
>> called from a servlet.
>>
>> When the session bean calls create on the home interface
>> object of the
>> entity bean it wants to create, the create method seems to
>> execute properly
>> and returns null. This seems true reguardless of which of two
>> create()
>> methods I call.
>>
>> After the create() method returns but before the next line of code is
>> executed, Orion throws the following exception:
>>
>> java.lang.NullPointerException
>>         at
>> CrHome_EntityHomeWrapper7.hashCode(CrHome_EntityHomeWrapper7.java:127
>> )
>>         at com.evermind.util.ExternalHashSet.get(JAX)
>>         at
>> CrHome_EntityHomeWrapper7.create(CrHome_EntityHomeWrapper7.java:335)
>>         at
>> com.regtek.slsb.CreateNewCRBean.makeNew(CreateNewCRBean.java:41)
>>         at
>> CreateNewCR_StatelessSessionBeanWrapper2.makeNew(CreateNewCR_Stateles
>> sSessionBeanWrapper2.java:54)
>>         at com.regtek.protocol_servlets.MakeCR.doPost(MakeCR.java:92)
>>         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
>>         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
>>         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
>>         at com.evermind.server.http.d1.si(JAX)
>>         at com.evermind.server.http.d1.forward(JAX)
>>         at com.evermind.server.http.ed.sp(JAX)
>>         at com.evermind.server.http.ed.so(JAX)
>>         at com.evermind.util.f.run(JAX)
>>
>> Of course, I have a pile of code and descriptors, but didn't
>> want to post
>> all that. If it is necessary, I will do so. Its not that I
>> didn't want to,
>> but I'm not sure which of it is relevant to this problem and
>> posting all of
>> it would make for a very long message.
>>
>> If someone could give me an idea of how to solve this I would
>> appreciate
>> it. I went through the archives and saw one other posting
>> from Sep 22 from
>> someone who was having this exact problem, but I could find
>> no reply. I
>> sent that guy a note, and he wrote back telling me he gave up on it.
>>
>> I would post a bug in Bugzilla, but I'm not sure this is a
>> bug. It seems
>> too fundamental a problem to be a bug in Orion.
>>
>> Thanks very much.
>>
>> Jim
>>
>>
>>
>>





Reply via email to