This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing an ArrayList to a session bean by reference  RSS feed

 
M Burke
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am passing a ArrayList referance from a javabean in a web app to a session bean (using RMI), the session bean then fills the collection and returns. The ArrayList is filled ok inside the session bean, but when it returns to the javabean the ArrayList is empty.

So what am I missing?

JavaBean:

public class EJBClientBean {
...
protected ArrayList ans = new ArrayList();
...
protected String jndiInvAdd = "InvoiceSessionHome";
public boolean setInvoiceData(String inv){
boolean rc = true;
try {
invHome = (InvoiceSessionHome) HomeFactory.singleton().getHome(jndiInvAdd);
invRemote = invHome.create();
invRemote.callInvoiceEntity(inv, ans);

...


Session Bean:

public boolean callInvoiceEntity(String invKey, ArrayList all){
...


try {
InitialContext initialContext = new InitialContext();
Object homeObject = initialContext.lookup("InvoiceEntityHome");

InvoiceEntityHome IH =(InvoiceEntityHome) javax.rmi.PortableRemoteObject.narrow(homeObject,InvoiceEntityHome.class);
InvoiceEntity IL = IH.create(key);
Collection lall = IH.findAllInvoices();
Iterator pAll = lall.iterator();
while(pAll.hasNext()){
InvoiceEntity allIE = (InvoiceEntity) pAll.next();
inv = allIE.getInvName();
all.add(inv);
}

...
[ December 25, 2004: Message edited by: M Burke ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by M Burke:
So what am I missing?
Objects passed "by reference" via RMI are actually passed "by value." You need to return the modified ArrayList.
[ December 25, 2004: Message edited by: David Harkness ]
 
M Burke
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see, thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!