• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

isIdentical() clarification......

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Paul Codillo
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The specs is clear in its premis that the EJBObject references compared has to come from the same home.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>>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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic