Forums Register Login
Doubt from Spec

I have just started preparing for SCBCD.I am currently going through the EJB spec.

In the spec in the following paragraph i have a doubt (page 66)

" All session objects of the same stateless session bean within the same home have the same object identity,which is assigned by the container."

Here in the above statement i have the following doubts.

1. I am i right to say that "All session objects" means "All EJB Objects" ?If what i have understood is right then according to Head First each client gets his own EJBObject and his own bean.

So it means that if there is client A, then that client A will get EJBObject A and a bean A and for client B an EJBObjectB and a bean B.

so when we use isIdentical() method for checking whether two EJB Object is refering to the same bean it should result false always.But in the spec i found the following line which confuses me.

"The following example illustrates the use of the isIdentical method for a stateless session object.

FooHome fooHome = ...; // obtain home of a stateless session bean
Foo foo1 = fooHome.create();
Foo foo2 = fooHome.create();
if (foo1.isIdentical(foo1)) {// this test returns true
if (foo1.isIdentical(foo2)) {// this test returns true

My question is how in the second if statement the test returns true ?
If i have understood wrongly , pls correct me.
For stateless beans, the bean-client association happens only during a business method invocation. When an isIdentical() operation is performed, although the client can assume that it is comparing two EJBObject instances, the actual implementation (which is vendor independent) would just result in a comparison of their respective EJBHome-s.

Thanks for your reply.

Did you mean to say that for a stateless session bean, The isIdentical method compared the Home Object rather than the EJBObject since the EJBObject is create only when a client invokes the business method ?

So in this case it will always return true because a single Home Object
will be created and shared no matter how many EJBObject or session bean instances are created.
It is the container's discretion whether to create one or two EJBObject(s). And each container may do this differently, so this is purely a vendor implementation. There is no guarantee that you have 2 instances created from the same home. What is guaranteed is that calling isIdentical() would return true no matter how the container handles the creation. So you wouldn't really have to know whether the server created two different objects or is just using one.
That feels good. Thanks. Here's a tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database

This thread has been viewed 792 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 23, 2019 08:00:03.