• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

side effects in value object passed to session bean?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34669
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I pass a value object to a session bean and the bean makes a change to the object, is it reflected in the client's version?
For example, the client contains:

and the ejb contains:

After the call, will vo.getFieldTwo() return "testData2" or "ejbData"?
For normal (local) method calls, I would expect "ejbData" to be returned. When I ran it in my EJB, it looked like "testData2" was returned. Is this the expected behavior or am I doing something wrong?
(edited to fix last paragraph)
[ September 05, 2003: Message edited by: Jeanne Boyarsky ]
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is expected since a local call uses pass by reference. The results would be as you expected if it was a remote call.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if you've written a remote interface only, some appservers use pass-by-reference (a la local interfaces) if they detect that the call is actually local to the JVM. This feature can be disabled, though.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34669
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. The original post should have read:
For normal (local) method calls, I would expect "ejbData" to be returned. When I ran it in my EJB, it looked like "testData2" was returned. Is this the expected behavior or am I doing something wrong?
I do understand that local calls are pass-by-reference. Lasse, are you saying that EJB calls can be pass-by-reference or pass-by-value? In other words, I should not rely on it being pass-by-reference in my EJB.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you're talking about "local method call", are you implying that your EJB reference is an EJB local interface? In that case, it could by either pass-by-reference or pass-by-value depending on your application server's default behavior and whether you have overridden that default with the vendor-specific deployment descriptor.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34669
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse,
When you're talking about "local method call", are you implying that your EJB reference is an EJB local interface?

No. I only wrote about "local method calls" so nobody would answer about regular (J2SE) calls. Clearly that confused the issue. Sorry!
It looks like the answer to my question is that EJB parameters are pass by value. That makes sense as there is normally no reason to pass the parameters back.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic