[jboss-jira] [JBoss JIRA] Created: (EJBTHREE-1257) Equals() of remote reference to stateful session bean should be reflexive and fixed

eric.dubuis (JIRA) jira-events at lists.jboss.org
Thu Apr 10 11:50:54 EDT 2008


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

                 Key: EJBTHREE-1257
                 URL: http://jira.jboss.com/jira/browse/EJBTHREE-1257
             Project: EJB 3.0
          Issue Type: Bug
         Environment: JBoss 4.2.2.GA, Java JDK 1.6.0_05.
            Reporter: eric.dubuis


>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.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list