-
1. Re: EJB remote accesing case
frito Jan 22, 2003 2:25 AM (in response to jcesar)Hi,
IMHO, best practice should be to implement a method like this to B:
A getSuperClone();
returning a real instance of A.
Regards,
Frito -
2. Re: EJB remote accesing case
jcesar Jan 22, 2003 9:42 AM (in response to jcesar)I add a method to B, like this:
public A getSuperClone(){
return (A) super.clone();
}
and in the session bean.
public A doSomething(){
return B.getSuperClone();
}
BUT, still the RMI is sending back an instance of B.
I don't understand this behavior. I think RMI should marshall the object as A not as B. Is it a java RMI hole? or JBoss Hole?
comments welcomed.
Cesar. -
3. Re: EJB remote accesing case
petertje Jan 22, 2003 4:15 PM (in response to jcesar)clone() always gives a clone of the original object; casting can't fool the runtime system. So your method getSuperClone() still returns a B (put a of println(super.clone()); in your method and you'll see).
So what you have to is what the other reply suggested: create a _new_ A and return that one:
[pre]
public A getSuperClone()
{
A copy = new A();
A.setX = this.getX();
// etc.
return copy;
}
[/pre]