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 .
I think all are true. Comparing EJBObjects from the same home object using isIdentical() for stateless session beans always return true.
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
Joined: Aug 13, 2003
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....?
Joined: Oct 03, 2003
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 ]
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
Joined: Oct 03, 2003
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...
Joined: Mar 24, 2005
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.
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 ...
>>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.