File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes isIdentical() clarification...... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "isIdentical() clarification......" Watch "isIdentical() clarification......" New topic
Author

isIdentical() clarification......

Raja Sagar Panamgipalli
Ranch Hand

Joined: Aug 13, 2003
Posts: 109
Guys plz clarify the below question....

Given the client code (accessing stateless session bean),

The isIdentical(EJBObject otherEJBObject) and
isIdentical(EJBLocalObject otherEJBLocalObject) methods
returns true
when,

Answer: a. foo1.isIdentical(foo1) is called
b. "foo1.isIdentical(foo1) is called" and "
foo1.isIdentical(foo2) is called"
c. foo1.isIdentical(foo2) is called

i think 'a' is the right answer...is there a possibility that the container assigns the same EJBObject to foo1,foo2 both .

Thank you...


SCJP 1.4<br />SCBCD 1.3
Paul Codillo
Ranch Hand

Joined: Aug 21, 2002
Posts: 38
Originally posted by Raja Sagar Panamgipalli:
Guys plz clarify the below question....
Given the client code (accessing stateless session bean),

The isIdentical(EJBObject otherEJBObject) and isIdentical(EJBLocalObject otherEJBLocalObject) methods
returns true when,
Answer: a. foo1.isIdentical(foo1) is called
b. "foo1.isIdentical(foo1) is called" and "
foo1.isIdentical(foo2) is called"
c. foo1.isIdentical(foo2) is called
i think 'a' is the right answer...is there a possibility that the container assigns the same EJBObject to foo1,foo2 both .

Thank you...

I think all are true. Comparing EJBObjects from the same home object using isIdentical() for stateless session beans always return true.


paul.com<br />SCJP, SCWCD, SCBCD, SCEA
Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
I think so too. The purpose of the isIdentical() method is to compare the objects on the server. Since this is a stateless session bean, isIdentical will always return true.

Remember:
isIdentical will return
always TRUE: for stateless session beans.
always false: for stateful session beans.
TRUE : for entity beans if they have the same primary key.

I think i got it right.... :-)
[ May 01, 2005: Message edited by: linoops ]
Raja Sagar Panamgipalli
Ranch Hand

Joined: Aug 13, 2003
Posts: 109
Hi Linoops n Paul n others...

In the below case..for a stateless bean, the container may initially create a single EJBObject using a Home Object, when home.create() is called.

But its seems to be upto the container's discretion whether it creates two EJBObjects i.e.. foo1,foo2 but mostly a single in case of session beans.

Is this how it happens....?




Thank you...
Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
You are correct in saying that it is the container's discretion whether to create one or two objects. And each container may do this differently, what the EJB spec guarantees is that calling isIdentical() would return true no matter how the container handles the creation. So you don't really have to know whether the server created two different objects or is just using one.

Regards.
[ May 01, 2005: Message edited by: linoops ]
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Page 66, EJB 2.0 Specifications:


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

If a stateless session bean is deployed multiple times (each deployment results in the creation of a distinct home), session objects from different homes will have a different identity.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Paul Codillo
Ranch Hand

Joined: Aug 21, 2002
Posts: 38
The specs is clear in its premis that the EJBObject references compared has to come from the same home.
ShivPrakash Srivastava
Ranch Hand

Joined: Mar 24, 2005
Posts: 88
Hey but what happens if the bean b1 is a stateful session Bean or a Entity Bean.

bean1 = homeObject.create()

boolean b1 = b1.isIdentical(b1)

As far as I know for entity bean isIdentical()method compares the Primary Key.Will it still return true when compared with the same instance fro both the bean

Thanks
Shiv
Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
hmmm...When compared with the same instance for both the beans I think it will return true. isnt that what the method is for?

If we are not doing a b1.isIdentical(b1) then:
I think for stateful session beans it will always return false, since they have state information particular to a client and even though the state information might be the same they are for different clients. So always it will return false, unless as mentioned earlier it is compared with itself.

For entity beans, it will return true if the primary keys are the same.
(What happens when 2 clients ask for the same entity, doesn't the server create two ejbObjects each pointing to the same enity bean underneath??)

All these discussions help me understand things better.. javaranch rocks...

Cheers!
ShivPrakash Srivastava
Ranch Hand

Joined: Mar 24, 2005
Posts: 88
Hi,

No Doubt for Stateful Session Bean, but according to the spec,multiple Entity Bean can refer to the same primary key.Now when the Entity beans have different Home Interface then they will have different remote Interface,so how will isIdentical method() behave?

for eg:
bean1 and bean2 have different Home Interface but refer to the same primary key then what will be the result?

boolean b1 = bean1.isIdentical(b2)
Now we cannot use the Primarykey to UNIQUELY identify a bean.


Regards
Shiv
Anil Chandran
Greenhorn

Joined: Apr 11, 2005
Posts: 15
We need to consider isIdentical() same as equals() method.)
I am using same in the sense we are checking the remote objects for some meaningful equality.( Not same asthe checking for identity using == operator)

So for stateless session bean the the objects coming from the same home are meaningfully equivalent.
For entity bean , if the beans are representing the same entity in DB and we are checking their EJBObjects using isIdentical,they are meaningfully equal.So it will return true.


I started out with nothing..I still have most of it ...
Sumitro Palit
Ranch Hand

Joined: Dec 13, 2003
Posts: 37
>>For entity bean , if the beans are representing the same entity in DB and >>we are checking their EJBObjects using isIdentical,they are meaningfully >>equal.So it will return true.

If there are 2 different entitybean "types" associated with the same entity data in the DB (say AddrBean1 & AddrBean2 for arguments sake), then even if there are 2 instances , one corresponding to each home, representing the same entity data in the DB, isIdentical will return false => they must be from the same home to be treated as identical.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: isIdentical() clarification......