• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

side effects in value object passed to session bean?

 
author & internet detective
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic