Hi ,

I'm encountering a paradox, or possibly a bug, in the CMR value-objects 
generated code... or maybe I need to re-think my design ?? 
please tell me your thoughts re: the following ::

In a 1:N relationship, code is added to the 1-side of the relationship to 
add, update, and remove the n-side elements from the collection. One can 
effectively operate strictly on the Bean's valueObject, and then call on the bean's 
"setValueObject" method to handle the database synchronization. 

However, in the 1:1 relationship, there is no such code. The setting and 
updating of the right hand side of the relationship is handled within the 
setValueObject and getValueObject of the left hand side. 
But what I'm finding paradoxical is that this code pre-supposes the 
existence of a PK for the dependent value object, without ever providing 
the facility to generate this PK (or rather create a new database row for 
the object) 

The implication then is that the Session or the Client is responsible for 
the creation of the Dependent Value Object's database row before it can be 
passed to the parent object. This contradicts the design pattern for a 
value object!

Here is the XDoclet-generated code which illustrates this : 

public void setPersonValue( rpmaster.server.data.beans.PersonValue 
valueHolder )
   {
        //      .... set CMP fields here ... 

        // Checks for null aggregate
        if (valueHolder.getCreditCardValue() != null)
        {
                 java.lang.Integer pk = 
valueHolder.getCreditCardValue().getCreditCardUId();

                 rpmaster.server.data.beans.CreditCardLocalHome home = 
rpmaster.server.data.beans.CreditCardUtil.getLocalHome();

           //here we call findByPrimaryKey.. but what if primary key is null ? 
EXCEPTION! that's whats happening to me!
                 rpmaster.server.data.beans.CreditCardLocal relation = 
home.findByPrimaryKey(pk);
                 
                relation.setCreditCardValue(valueHolder.getCreditCardValue());
        }



I am getting thrown a Null Pointer Exception right at that line 
(findByPrimaryKey) because I am trying to pass a ValueObject to its parent 
ValueObject which does not have a PrimaryKey. 

So, how am I supposed to do this ? Should I always take care to create a 
new EJB so that I have a primary key, before I pass it to the parent VO ? 

Or is there a way for XDoclet to either
a) auto create a new PK if it catches a null one and insert a new row 
or b) auto create the dependent value object upon construction, so that 
there is always a PK for that 1:1 relationship, regardless of whether the 
client has inserted any data into that row ? 


any advice is greatly appreciated

Thanks
Nathaniel





-------------------------------------------------------
This SF.net email is sponsored by: Does your code think in ink? 
You could win a Tablet PC. Get a free Tablet PC hat just for playing. 
What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user

Reply via email to