File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes side effects in value object passed to session bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "side effects in value object passed to session bean?" Watch "side effects in value object passed to session bean?" New topic
Author

side effects in value object passed to session bean?

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

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 ]

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

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.
 
 
subject: side effects in value object passed to session bean?