isIdentical?

how to find out if two stubs refer to the same bean

image with no caption

These twins are identical if they’re stateLESS, since they can each do the same thing and clients won’t know the difference. But if they’re stateFUL, then they are always distinct. Stateful twins cannot be identical, because they can hold information specific to their own unique client.

<<interface>>

EJBObject

Object getPrimaryKey()

EJBHome getEJBHome()

Handle getHandle()

void remove()

boolean isIdentical(Object o)

If you’ve got two stubs, and you want to know if they refer to the same bean, you call isIdentical on one reference, passing in the reference you want to compare it against. Just like the way you use the equals() method.

The trick is, stateless session beans, stateful session beans, and entity beans each have different rules for what causes isIdentical() to return true.

Stateless session beans

True if both references came from the same home, even if the stubs are referring to two different Remote EJB objects! To the server, one stateless bean is as good as any other bean from the same home, because the client would never be able to tell the difference (since the bean can’t hold any client-specific state).

Stateful session beans

False no matter what, for any two unique stubs, even if from the same home. After all, my shopping cart isn’t the same as yours!

Entity beans

True if the stubs refer to two entities with the same ...

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.