-
1. Re: How to find out if two home objects refer to the same be
andreas Mar 1, 2002 8:23 AM (in response to lolsson)> I have tried to use EJBHome.equals() but it seems to
> refer true for for EJBHome's that are different:
> EJBHome b1 = (EJBHome)ctx.lookup("B1");
> EJBHome b2 = (EJBHome)ctx.lookup("B2);
> System.err.println(b1.equals(b2));
> This produces 'true' even though b1 and b2 refer to home interfaces of different beans.
Hmmm, b1 and b2 should be instances of different classes (i.e. B1Home and B2Home)
Check, if b1.getClass().getName() is the same as b2.getClass().getName() (I assume it's proxy.)
If not B1Home.class.isInstance(b1) and B2Home.class.isInstance(b1), check Your deployment descriptor. Maybe B1 and B2 indeed assignd to the same home interface. -
2. Re: How to find out if two home objects refer to the same be
chuang88 Mar 1, 2002 12:41 PM (in response to lolsson)try the followings:
EJBHome b1 = (EJBHome)ctx.lookup("B");
EJBHome b2 = (EJBHome)ctx.lookup("B");
EJBObject e1 = b1.findByPrimaryKey(k1);
EJBObject e2 = b1.findByPrimaryKey(k1);
//e1 and e2 should be the same bean -
3. Re: How to find out if two home objects refer to the same be
lolsson Mar 2, 2002 2:00 PM (in response to lolsson)> Maybe B1 and B2 indeed assignd to the same home interface.
No - here is another test program:
EJBHome h1 =(EJBHome)ctx.lookup("wis/ejb/boxmgr");
Class h1class = h1.getClass();
System.out.println("h1=" + h1 + ", h1class=" +h1class.getName());
EJBHome h2 = (EJBHome)ctx.lookup("wis/ejb/usermanager");
Class h2class = h2.getClass();
System.out.println("h2=" + h2 + ", h2class=" + h2class.getName());
boolean h1_is_h2class = h2class.isInstance(h1);
System.out.println("(h1 instanceof h2class) = " + h1_is_h2class);
boolean h2_is_h1class = h1class.isInstance(h2);
System.out.println("(h2 instanceof h1class) = " + h2_is_h1class);
boolean eq = h1.equals(h2);
System.out.println("(h1==h2) = " + eq);
and here is the output:
h1=wis/ejb/boxmgrHome, h1class=$Proxy0
h2=wis/ejb/usermanagerHome, h2class=$Proxy1
(h1 instanceof h2class) = false
(h2 instanceof h1class) = false
(h1==h2) = true -
4. Re: How to find out if two home objects refer to the same be
lolsson Mar 2, 2002 2:04 PM (in response to lolsson)> EJBObject e1 = b1.findByPrimaryKey(k1);
> EJBObject e2 = b1.findByPrimaryKey(k1);
My beans are stateless session beans so I assume
the findByPrimaryKey() operation cannot be used.
I could of course use introspection to find the
create() method and call that to create the beans
to be able to perform the comparison.
Lars