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 ....

