My question is: will statefulBean always have the same reference or will it somehow differ at each call of doSomething()?
Here is what the EJB specification states about it:
3.4.7.1Stateful 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 or no-interface view references refer to the same session object by use of the equals method.
For example,
@EJB Cart cart1;
@EJB Cart cart2;
...
if (cart1.equals(cart1)) { // this test must return true
...
}
...
if (cart1.equals(cart2)) { // this test must return false
...
}
All stateful session bean references to the same business interface for the same stateful session bean instance will be equal. All references to the no-interface view of the same stateful session bean instance will be equal. Stateful session bean references to different interface types or between an interface type and a no-interface view or to different session bean instances will not have the same identity.
This means that once the client has acquired a reference to a stateful session bean that bean is bound to the client. The client can set and read the states of the bean. When the client is finished it must inform the server that the bean should be destroyed by invoking a method annotated by a @Remove
annotation.