This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes BEA/Weblogic and the fly likes Pass by reference problem in EJB's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "Pass by reference problem in EJB Watch "Pass by reference problem in EJB New topic
Author

Pass by reference problem in EJB's

Ashutosh Shinde
Ranch Hand

Joined: Jun 07, 2001
Posts: 42
Hello All,
I am passing a Object between two Stateless Session Beans (say A and B). I have printed the hashcode of the Object passed in A before passing the Object and in B after receiving the Object. Surprisingly, i find the values to be different.
I have enabled the pass by reference in the weblogic-ejb-jar.xml using <enable-call-by-reference>True</enable-call-by-reference>.
Because of this discrepancy I find that I am not able to retrieve the values set on the Object by Bean B in Bean A..
What could be going wrong?
Thanks,
Ashutosh
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Are u changing the object in B?


Groovy
Ashutosh Shinde
Ranch Hand

Joined: Jun 07, 2001
Posts: 42
Infact I am printing the hash code immediately after the Object is received in the Bean B. So, there is no way the Object is being changed.
But, is this behaviour expected?
Ashutosh
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

I am bit surprised by the behavior..Call by reference is set to true by default, one need not set it explicitly in weblogic-ejb-jar.xml.
Remember that 2 session beans must be in the same server.
Change the value of the element to "true" from "True".. Lemme know the result
Ashutosh Shinde
Ranch Hand

Joined: Jun 07, 2001
Posts: 42
Hi Pradeep,
I have already set the value to "True". It does not help though. Is it that I have to create a EAR file for the Application and only then the Pass-By-Reference works ?!?
Ashutosh
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Pass by reference only kicks in when the two EJBs (or servlet and ejb) are in the same "deployment unit".
So if you deploy two separate ejb-jars they will not normally pass-by-reference. If you put your ejbs in one jar or assemble the two ejb jars into an enterprise app (ear) then you will get pass-by-reference.
What's going on is:
Each thing you deploy is turned into an enterprise app if it is not already (look in config.xml and you'll see an Application element wrapping each one).
Each application has its own ClassLoader. So if you have two classes (like the Remote interface or some serializable parameter object) there will actually be two versions of these classes loaded - one by each ClassLoader.
Now when WLS goes to make a "local" (same VM) call on a Remote interface, it checks if both ends know about the same classes. If not, it has to Serialize no matter the setting of pass-by-reference.
If it did not, you would get ClassCastExceptions because even though the classes have the identical name, the instance of the class object loaded by different ClassLoaders is different, thus they are actually different classes to the VM.
So the two ways to fix this are:
Deploy everything you want to pass-by-reference in the same unit - assemble into ear or into one ejb-jar.
Or put all your classes in the system CLASSPATH. This defeats hot-deploy, and goes against the spirit of J2EE and deployable components - so I don't recommend it. But since all classes will be loaded by the system ClassLoader, WLS will see that serialization is not necessary.

The exact same conditions apply to EJB Local interfaces - they can only be used within the same application.
Ashutosh Shinde
Ranch Hand

Joined: Jun 07, 2001
Posts: 42
Thanks Dave. You made it very clear!
I think we would stick to creating an EAR instead of modifying the System classpath.
Thanks again .
Ashutosh
 
 
subject: Pass by reference problem in EJB's
 
Similar Threads
AXIS Generated WSDL file looks wrong.
How to look up the JNDI in Aun App server (version 8)
weblogic 10.3.2 remote-client-timeout not working
Local Home / Remote Interface in a clustered environment
Can I pass a bean to a javascript function within a html:iterate tag?