Problems with XDoclet and Value Object generation for CMR relationships

K

Kenneth Aitken

I would appreciate help/feedback, because this is affecting our ability
to create useful code on the EJB session beans to call EJB entity beans.

I am running XDoclet Version 1.2 Beta 3. I will use an example of a 1:1
relationship, because it is much less complicated.
I am creating the necessary xxxCMP and xxxValue files using the
ejb.value-object tag, such as this in a CustomerBean:
/**
* @ejb.interface-method
* view-type="local"
* @ejb.relation
* name="Customer-Address"
* role-name="customer-has-address"
* relation-name="customer-has-address"
* target-ejb="Address"
* target-role-name="address-belongs-to-customer"
* target-multiple = "no"
* target-cascade-delete = "yes"
* @jboss.relation
* fk-column = "customeraddress"
* related-pk-field = "addressID"
* @jboss.relation-mapping
* style = "foreign-key"
* @ejb.value-object
* compose="com.foobar.value.AddressValue"
* compose-name="AddressValue"
* members="com.foobar.interfaces.AddressLocal"
* members-name="Address"
* relation="external"
* match="*"
*/
public abstract AddressLocal getAddress();
/**
* @ejb.interface-method
* view-type="local"
*/
public abstract void setAddress(AddressLocal address);

The problem is that it generates CMP code that either allows EJB Entity
Bean relationships to be set (when aggregate and aggregate-name are
used) or Entity Bean values to be set (when compose and compose-name are
used), but why only one without the other?

Moreover, why does the generated CMP code not allow for creation of new
entities, such as when the ID-field has not been set? This contradicts
the documentation on XDoclet's website: "This means that the generated
accessor methods for this relationship will create and remove Address
entities when adding and removing them via the generated addAddress()
and removeAddress() methods."
http://xdoclet.sourceforge.net/valueobjects.html

Here the CustomerCMP file would look like this, where the Address object
is set using the AddressValue object, but the relationship between
Customer and Address is not set (i.e. compose and compose-name have been
used):
public void setCustomerValue( com.foobar.CustomerValue valueHolder )
{
try
{
//Set Customer members from values

// Anonymous block to allow variable declations without conflicts
{
// Checks for null composition
if (valueHolder.getAddressValue() != null)
{
java.lang.String pk =
valueHolder.getAddressValue().getAddressID();
com.foobar.interfaces.AddressLocalHome home =
com.foobar.util.AddressUtil.getLocalHome();
com.foobar.interfaces.AddressLocal relation =
home.findByPrimaryKey(pk);
relation.setAddressValue(valueHolder.getAddressValue());
}
}
}
catch (Exception e)
{
throw new javax.ejb.EJBException(e);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top