ejbCreate and ValueObjects

Hey there ...

the following question might sound trivial but I'm just not getting it.

[ejb2.1 / JBos'plugin']

I'm creating a vo of customer. I don't set the ID, since it's generated by customers generateGUID. In ejbCreate I'm using the vo reference to set all the values except the ID.

To reuse the vo of the customer after creation I set the generated ID for the customer and the customer value.

Now the weird thing;

The ID of the customerValue is set in the ejbCreate. However, it is null when I return to the point where I created it. It's call by reference right?!

CustomerBean:

public java.lang.String ejbCreate(CustomerValue customerValue)

throws javax.ejb.CreateException{

// EJB 2.0 spec says return null for CMP ejbCreate methods.

// TODO: YOU MUST INITIALIZE THE FIELDS FOR THE BEAN HERE.

// setMyField("Something");

// begin-user-code

setGenericID(CustomerUtil.generateGUID(this));

setFirstName(customerValue.getFirstName());

setFamilyName(customerValue.getFamilyName());

customerValue.setPrimaryKey(getGenericID());

returnnull;

// end-user-code

}

TestClient:

try{

CustomerValue customerValue =new CustomerValue();

customerValue.setFirstName("John");

customerValue.setFamilyName("Doe");

CustomerHome ch = getHome();

Customer customer = ch.create(customerValue);

customerValue.getPrimaryKey()// returns null

}catch ....

[2131 byte] By [Ossaha] at [2007-10-3 4:37:22]
# 1

You should really read a bit about distributed computer. This is a very basic misunderstanding on your part.

The actual object (and thus the actual reference) your client application has is quite different from the one your EJB has.

The client application sends a serialised form of the object across the network to the application server where it's deserialised and recreated as a new instance.

The two instances know nothing about each other.

So calls to EJBs are effectively NOT pass by reference. Neither are they strictly pass by value because the value as seen by the calling object cannot be changed by the callee.

jwentinga at 2007-7-14 22:41:05 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...