Hi,

this looks like a problem with the verifier, when checking the object
equality it attempts to create two primary key objects and then compares
their hashcodes.

In your case however, each call to the constructor creates a new id which
won't match the previously created hashcode.

Need to fix that.

-- Juha


On Mon, 30 Oct 2000, Tim Squires wrote:

> Hey Chaps,
> 
> I have the following errors appearing on deployment of an entity EJB with a 
> single primary key, the value of the primary key being populated from an 
> Oracle sequence:
> 
> [Verifier]
> Class  : area_type
> Section: 9.2.9
> Warning: The primary key class must override equals().
> 
> [Verifier]
> Class  : area_type
> Section: 9.2.9
> Warning: The primary key class must override hashCode().
> 
> Using prod-3 on NT with JDK1.3.
> 
> The primary key code is:
> 
> package com.mywds.beans;
>  
> import javax.naming.*;
> import java.sql.*;
> import javax.sql.*;
> import com.mywds.util.*;
> 
> public class area_typePK implements java.io.Serializable
> {
>   public Integer id;
> 
>   //Assuming that this bean will be implemented on an Oracle database
>   //it uses the area_typePK_seq to retrieve the next primary key integer.
>   public area_typePK()
>   {
>     //Connect to the database
>     Connection conn = null;
>     try
>     {
>         Context ctx = new InitialContext();
>         DataSource ds = (DataSource)ctx.lookup("jdbc/OraclePool");
>         conn = ds.getConnection();
> 
>         //Find the next free integer from the area_typePK_seq sequence
>         Statement stmt = conn.createStatement();
>         ResultSet query = stmt.executeQuery( "select area_typePK_seq.nextval 
> pk from dual" );
> 
>         if ( query.next() )
>           this.id = new Integer( query.getInt( "pk" ));
>         //else
>           //throw new Exception( "area_typePK: No area_type primary key 
> returned from area_typePK_seq." );
> 
>         query.close();
>         query = null;
>         stmt = null;
> 
>     }
>     catch(NamingException ne)
>     {
>       //throw new Exception( "area_typePK: Hello Tim: Unable to connect to 
> JNDI server to retrieve context: "+ne.toString() );
>     }
>     catch(SQLException se)
>     {
>       //throw new Exception( "area_typePK: Problem executing SQL: 
> "+se.toString() );
>     }
>     finally
>     {
>       if(conn != null)
>               try
>         {
>           conn.close();
>           conn = null;
>         }
>         catch(SQLException e)
>         {
>          //throw new Exception( "area_typePK: Unable to close current 
> connection: "+e.toString() );
>         }
>     }
> 
>   }
> 
>   public area_typePK( int id )
>   {
>     this.id = new Integer( id );
>   }
> 
>   public area_typePK( Integer id )
>   {
>     this.id = id;
>   }
> 
> 
>   public int hashCode()
>   {
>     Integer hc = new Integer( id.toString() );
>     return hc.intValue();
>   }
> 
>   public boolean equals( Object obj )
>   {
>     if ( obj == null || !(obj instanceof area_typePK))
>       return false;
>     else if (((area_typePK)obj).id == id )
>       return true;
>     else
>       return false;
>   }
> 
>   public String toString()
>   {
>     return id.toString();
>   }
> 
> }
> 
> 
> If I change equals to always return true and the hashCode to always return 1, 
> jBoss does not throw the above error.
> 
> Any help, hints or examples would be great.
> 
> Thanks for your time,
> Tim.
> 
> ---------------------
> It's not what you know, it's who you tell.
> 
> -----------------------
> "Free text messages!!! Another 100% free service brought to you by the award winning 
>Totalise"
> Visit http://sms.totalise.net"
>     
> 
> 
> 
> --
> --------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Problems?:           [EMAIL PROTECTED]
> 
> 



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to