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 Strange EJB Behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Strange EJB Behaviour" Watch "Strange EJB Behaviour" New topic
Author

Strange EJB Behaviour

Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

My servlet calls an ejb deployed in the same app server (WebLogic) passing reference to an object. This object is serializable and the its a remote call to the ejb.
I have oserved a difference in the state of the object when application is deployed as EAR and when it is deployed in exploded form.
Such a difference is not expected. The ejb should not be able to change the state.
Can you throw some light on this.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Could you elaborate on how the "EJB's state changes"?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

Not the EJB, the Object whose reference is passed gets its state changed.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

Objects are passed by reference when both the war and jar are in the same ear file.


Groovy
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by abhinav srivastava:
Not the EJB, the Object whose reference is passed gets its state changed.

uhhm :-(. I have heard that weblogic optimizes remote calls / rather calls to remote EJBs if it figures out that the caller and the EJb are in the same VM (by making it a local invocation).
Now I did'nt know that it does'nt respect the pass-by value semantics in that case. The pass by reference behaviour that you are referring to w'd have been ok if it had been an EJB with Local interfaces.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Pradeep Bhat:
Objects are passed by reference when both the war and jar are in the same ear file.

Is this documented somewhere / is it there in some book ? I find this strange. When i use a remote EJB, dont I always program assuming that "pass-by-value" semantics will be respected. I mean the parameters passed to a remote EJb if serializable has to be a pass by value?
I guess many applications do have the war and the jar packaged together in a ear.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The specification states that remote calls should use pass-by-value. WebLogic deliberately breaks that part of the specification by default but provides a way of forcing pass-by-value: http://edocs.bea.com/wls/docs61/ejb/reference.html#1070257
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

Weblogic Application Server is hosting both Servlets and EJBs. It seems that in case of an EAR file, its pass by refrence and in case of Exploded deployment its pass by value.
Haven't found any documentation in support of this though thats the way it is.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Lasse Koskela:
The specification states that remote calls should use pass-by-value. WebLogic deliberately breaks that part of the specification by default but provides a way of forcing pass-by-value: http://edocs.bea.com/wls/docs61/ejb/reference.html#1070257

you guys are just awsome! I guess the developers @ your place need not look up weblogic docs / EJB Spec when they code. They probably just have to turn and ask :-).
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
you guys are just awsome! I guess the developers @ your place need not look up weblogic docs / EJB Spec when they code. They probably just have to turn and ask :-).

Thanks for the ego boost
By the way, WebSphere also has this pass-by-value/pass-by-reference switch (at least in the previous version) but I think the default behaviour was spec-compliant.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

Oracle 9iAS also supports pass by value.
You make use of copy-by-value tag in orion-ejb-jar.xml .
Whether or not to copy (clone) all the incoming and outgoing parameters in EJB calls. Set to 'false' if you are certain that your application does not assume copy-by-value semantics for a speed-up. The default is 'true'.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Oracle 9iAS also supports pass by value.

All certified J2EE implementations must support pass-by-value. What they can support is the non-compliant pass-by-reference. Then there's the question of which one is the default.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

Sorry ..I typed it wrongly .. it is pass by reference
The default is pass by value as mentioned in my previous post.
[ August 14, 2003: Message edited by: Pradeep Bhat ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange EJB Behaviour
 
Similar Threads
pool & cache
Stateless Session bean pooling? What's that?
http session object,ejb session bean
Doubt on EJBObject
Difference between EJB Object and EJB Instance