Uploaded image for project: 'EJB 3.0'
  1. EJB 3.0
  2. EJBTHREE-319

hashCode and equals method definitions are ignored in Session beans

    XMLWordPrintable

Details

    • Bug
    • Resolution: Obsolete
    • Major
    • None
    • EJB 3.0 RC3
    • None
    • None

    Description

      An equals or hashCode method in a Session bean class is ignored for the final bean objects. There seems to be some internal implementation of these two methods and it cannot be overrided.

      For example:

      Test.java
      ========

      public interface Test { }

      TestBean.java
      ============

      @Stateless
      public class TestBean implements Test
      {
      public boolean equals(Object obj)

      { return true; }

      public int hashCode()

      { return 5; }

      }

      Client code
      ==========

      InitialContext ctx = new InitialContext();
      Test test = (Test) ctx.lookup(Test.class.getName());
      if (!test.equals("anything"))
      System.err.println("this is wrong");
      if (test.hashCode() != 5)
      System.err.println("this is also wrong");

      Both of those error messages are printed, when in fact neither should be printed since the equals() method should always return true in this case, and the result of hashCode() should always be 5.

      Attachments

        Activity

          People

            Unassigned Unassigned
            gregnolle_jira Gregory Nolle (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: