I had this problem with the WebLogic server.  It turned out that in the
Persistence properties section of the DeployerTool, I was specifying (I'll
use your class and field names here) both a "Primary key type" of
"person.PersonPK" and a "Primary key field" of  "personid_" .  When I left
the "Primary key field" entry at its default value of "(none)" it worked
correctly.  Maybe you have made a similar mistake?

Bill Messick


----- Original Message -----
From: Scott Ellis <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 26, 2000 1:30 PM
Subject: Re: Primary key class in container managed entity bean, int type


> My problem is that the code that produces the error is generated by ejbc.
I
> can't make that change.  Rather, I have to somehow change how I define the
> primary key class, the home interface, or the deployment descriptor to
make
> the generator understand that the primary key class cannot be directly
> compared to a native type, but should call the equals method of the
primary
> key class that I have defined.
>
> Does that make more sense?
>
> -----Original Message-----
> From: Juan Pablo Lorandi [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 26, 2000 10:08 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Primary key class in container managed entity bean, int
> type
>
>
> use
> pk.personid_ = bean.personid_;
>
> instead... if that's not what you are asking, elaborate a little further
>
> -----Original Message-----
> From: Scott Ellis [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 26, 2000 1:10 PM
> To: [EMAIL PROTECTED]
> Subject: Primary key class in container managed entity bean, int type
>
>
> I cannot seem to make this work no matter what I do.  I want to create a
> primary key class that contains an integer as the primary key, and the
table
> I am trying to access a table called person, which I've created just to
see
> if I can get this to work.
>
> I've included all of the source below, exluding the deployment
descriptors,
> but I definitely name the person.PersonPK as the primary key class.  The
> problem is that the code for the bean implementation is attempting to set
an
> instance of my primary key class to the value of my bean's instance of
> personid_:
>       person.PersonPK pk = null;
>       try {
>         bean.ejbCreate(  arg0, arg1, arg2, arg3);
>         pk = bean.personid_;
>       ....
> You see that pk is of type person.PersonPK, and bean.personid_ is an int.
> Of course this is a compiler error.  Can anyone tell me what I am doing
> wrong?
>
> Home interface:
>
> package person;
>
> import javax.ejb.CreateException;
> import javax.ejb.EJBHome;
> import javax.ejb.FinderException;
> import java.rmi.RemoteException;
>
> public interface PersonHome extends EJBHome
> {
>   public Person create( int id, String name, String address, String
phone )
> throws CreateException, RemoteException;
>         public Person create( int id ) throws CreateException,
> RemoteException;
>   public Person findByPrimaryKey( PersonPK pid ) throws FinderException,
> RemoteException;
>   public Person findPerson( String name ) throws FinderException,
> RemoteException;
> }
>
> Remote Interface:
>
> package person;
>
> import java.rmi.RemoteException;
> import javax.ejb.*;
>
> public interface Person extends EJBObject
> {
>   public void setName( String name ) throws RemoteException;
>   public void setAddress( String address ) throws RemoteException;
>   public void setPhoneNumber( String phoneNumber ) throws RemoteException;
>
>   public String getName() throws RemoteException;
>   public String getAddress() throws RemoteException;
>   public String getPhoneNumber() throws RemoteException;
> }
>
> PersonPK.java:
>
> package person;
>
> import java.io.Serializable;
>
> public class PersonPK implements Serializable
> {
>   public int personid_;
>
>   public PersonPK( int id )
>   {
>     this.personid_ = id;
>   }
>
>   public PersonPK() {}
>
>   public int hashCode()
>   {
>     Integer i = new Integer( personid_ );
>     return i.hashCode();
>   }
>
>   public boolean equals( Object o )
>   {
>     if( o instanceof PersonPK )
>     {
>       Integer i = new Integer( personid_ );
>       Integer oi = new Integer( ((PersonPK)o).personid_ );
>       return i.equals( oi );
>     }
>     else
>       return false;
>   }
>
>   public String toString()
>   {
>     return Integer.toString( personid_ );
>   }
> }
>
> PersonBean.java:
>
> import javax.ejb.EntityContext;
>
> public class PersonBean implements EntityBean
> {
>   private   EntityContext       ctx_;
>
>   public    int                 personid_;
>   public    String              name_;
>   public    String              address_;
>   public    String              phone_;
>
>   private transient boolean     isDirty_;
>
>   // Getters and Setters
>   public void setName( String name )                { name_ = name; }
>   public void setAddress( String address )          { address_ =
address; }
>   public void setPhoneNumber( String phoneNumber )  { phone_ =
phoneNumber;
> }
>   public String getName()                           { return name_; }
>   public String getAddress()                        { return address_; }
>   public String getPhoneNumber()                    { return phone_; }
>
>   // EJB Required methods
>   public void setEntityContext( EntityContext ctx ) { this.ctx_ = ctx; }
>   public void unsetEntityContext()                  { this.ctx_ = null; }
>   public boolean isModified()                       { return isDirty_; }
>   public void setModified( boolean flag )           { isDirty_ = flag; }
>   public void ejbActivate()                         {}
>   public void ejbPassivate()                        {}
>   public void ejbLoad()                             {}
>   public void ejbStore()
                           { setModified( false );
> }
>   public void ejbRemove()                           {}
>   public void ejbPostCreate( int id )           {};
>   public void ejbPostCreate( int id, String name, String address, String
> phone ) {}
>
>   public PersonPK ejbCreate( int id ) throws CreateException
>   {
>     this.personid_ = id;
>
>     return null;
>   }
>
>   public PersonPK ejbCreate( int id, String name, String address, String
> phone ) throws CreateException
>   {
>     this.personid_ = id;
>     this.name_ = name;
>     this.address_ = address;
>     this.phone_ = phone;
>
>     return null;
>   }
> }
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to