O'Reilly logo

Head First EJB by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required