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

Equals() of remote reference to stateful session bean should be reflexive and fixed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.0.0-Beta1
    • AS 4.2.2.GA
    • None
    • None

      From the EJB 3 specification we can learn:

      3.4.5.1 Stateful Session Beans
      A stateful session object has a unique identity that is assigned by the container at the time the object is
      created. A client of the stateful session bean business interface can determine if two business interface
      references refer to the same session object by use of the equals method.

      The following JUnit test fails:

      @Test public void testIdentity1() throws Exception

      { Context jndiContext = new InitialContext(); CustomerManager cm = (CustomerManager) jndiContext .lookup("CustomerManagerBean/remote"); assertEquals(cm, cm); }

      The implementation of CustomerManager is a stateful session bean. Code sketch is:

      @Stateful
      @Remote(CustomerManager.class)
      public class CustomerManagerBean implements CustomerManager {
      // details not shown, irrelevant
      }

      Moreover, if a client uses the reference then it changes its identity! For example:

      @Test public void testIdentity1() throws Exception

      { Context jndiContext = new InitialContext(); CustomerManager cm = (CustomerManager) jndiContext .lookup("CustomerManagerBean/remote"); System.out.println(cm + ", hash: " + cm.hashCode()); System.out.println(cm + ", hash: " + cm.hashCode()); System.out.println(cm + ", hash: " + cm.hashCode()); }

      prints:

      [junit] ------------- Standard Output ---------------
      [junit] jboss.j2ee:jar=sales.jar,name=CustomerManagerBean,service=EJB3:432f6w1d-y33mrb-fevi3epi-1-fevi3euq-4, hash: 313698436
      [junit] jboss.j2ee:jar=sales.jar,name=CustomerManagerBean,service=EJB3:432f6w1d-y33mrb-fevi3epi-1-fevi3euq-6, hash: 313698438
      [junit] jboss.j2ee:jar=sales.jar,name=CustomerManagerBean,service=EJB3:432f6w1d-y33mrb-fevi3epi-1-fevi3euq-8, hash: 313698440
      [junit] ------------- ---------------- ---------------

      (Notice the changing of the string representation of the reference as well as the hash code.)

      To my understanding, the above illustrated behavior does not comply to the specification.

              arubinge@redhat.com Andrew Rubinger (Inactive)
              eric.dubuis eric.dubuis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: