I have defined a bi-directional, one-to-many CMR in two EJBs (PerformancePlan and
AssignedPerformanceElement) as seen below. Each of these EJBs has an associated
ValueObject. The PerformancePlanValue contains a Collection of
AssignedPerformanceElements, and there are a number of additional Collections
that represent the AssignedPerformanceElements that have been added, updated, or
removed.
I have created my EJBs as having ONLY local interfaces, and thus I have wrappered
them with a Session bean that is responsible for managing the interactions with
the client (a Struts application in this case). One of the methods available to
the Struts application is seen below. It takes as a parameter, an instance of a
PerformancePlanValue (presumably with some changes that need to be updated, and
persisted). Of particular interest here is the adding, creating, or removing of
AssignedPerformanceElements.
In my code that calls updatePerformancePlan(PerformancePlanValue ppv), I place a
new AssignedPerformanceElementValue object into the PerformancePlanValue object
by calling
addAssignedPerformanceElement(gov.doe.eia.pms.AssignedPerformanceElementValue
added).
Unfortunately, when I get into the
add(gov.doe.eia.pms.AssignedPerformanceElementValue added) method in
PerformancePlanCMP, there's a section of code (seen below) that is dynamically
generated. No where in this section of code is there a call to
setPerformancePlan(PerformancePlanLocal preformancePlan). This seems like a
local place to add the reference to the parent object.
When the EJB container attempts to persist the new AssignedPerformanceElement
into the database, there's an execpted error:
javax.ejb.CreateException: Could not create entity:java.sql.SQLException:
ORA-01400: cannot insert NULL into
("HR"."ASSIGNEDPERFORMANCEELEMENT"."PERFORMANCEPLANID")
Is it my responsiblity as the EJB developer to do something that I'm not doing to
ensure that my relationships are referenced properly when I use ValueObjects? Am
I using the ValueObjects wrong? Is there something missing from XDoclet's
dynamically generated code?
Thanks.
Troy Poppe
----
public class PerformancePlanBean
{
...
/**
* @ejb.relation
* name =
"AssignedPerformanceElementsInAPerformancePlanRelation"
* role-name =
"AssignedPerformancePlanHasPerformanceElements"
* cascade-delete = "no"
*
* @ejb.interface-method
* view-type = "local"
*
* @ejb.value-object
* compose="gov.doe.eia.pms.AssignedPerformanceElementValue"
* compose-name="AssignedPerformanceElement"
* members="gov.doe.eia.pms.AssignedPerformanceElementLocal"
* member-name="AssignedPerformanceElement"
* relation="external"
* type="Collection"
*
* @return
*/
public abstract Collection getAssignedPerformanceElements();
/**
*
* @ejb.interface-method
* view-type = "local"
*
* @param performanceElements
*/
public abstract void setAssignedPerformanceElements(Collection
assignedPerformanceElements);
...
}
public class AssignedPerformanceElementBean
{
...
/**
* @ejb.relation
* name =
"AssignedPerformanceElementsInAPerformancePlanRelation"
* role-name =
"AssignedPerformanceElementInAPerformancePlan"
*
* @ejb.interface-method
* view-type = "local"
*
* @jboss.relation
* fk-column = "performancePlanID"
* related-pk-field = "performancePlanID"
*
* @author TPO
*/
public abstract PerformancePlanLocal getPerformancePlan();
/**
* @ejb.interface-method
* view-type = "local"
*
* @jboss.relation
* fk-column = "performancePlanID"
* related-pk-field = "performancePlanID"
*
* @author TPO
*/
public abstract void setPerformancePlan(PerformancePlanLocal
preformancePlan);
...
}
public PerformancePlanValue updatePerformancePlan(PerformancePlanValue
ppv)
{
PerformancePlanLocalHome pplHome = null;
PerformancePlanLocal ppl = null;
try
{
pplHome = PerformancePlanUtil.getLocalHome();
}
catch ( NamingException ex)
{
}
if ( ppv.getPerformancePlanID() == null )
{
// new PerformancePlan
// NOTE: should probably check if the user is in the
right role
// to be creating a performance plan.
try
{
ppl = pplHome.create(ppv);
}
catch ( CreateException ex )
{
}
}
else
{
// existing PerformancePlan
try
{
ppl =
pplHome.findByPrimaryKey(ppv.getPerformancePlanID());
ppl.setPerformancePlanValue(ppv);
}
catch ( FinderException ex )
{
}
}
return ppl.getPerformancePlanValue();
}
public void add(gov.doe.eia.pms.AssignedPerformanceElementValue added)
throws javax.ejb.CreateException
{
try
{
java.lang.Integer pk = added.getAssignedPerformanceElementID();
gov.doe.eia.pms.AssignedPerformanceElementLocalHome home =
gov.doe.eia.pms.AssignedPerformanceElementUtil.getLocalHome();
gov.doe.eia.pms.AssignedPerformanceElementLocal relation =
home.create(added);
getAssignedPerformanceElements().add(relation);
}
catch (Exception e){
if (e instanceof javax.ejb.CreateException)
throw (javax.ejb.CreateException)e;
else
throw new javax.ejb.EJBException(e);
}
}
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user