Dan,

I suggest that you talk to your vendor. The best way of dealing with this
is in the CMP provider.

<vendor>

With Sybase EAServer, you can simply map your 'storeNum' and 'store' cmp and
cmr fields to reference the same column name.

</vendor>

Dan Haywood wrote:

> Hello all - here's a problem that has me stumped.
>
> In EJB 2.0 using CMP and CMR, it seems that for a PK that is composite, with one 
>part being a foreign key to a "parent" entity (in other words an identifying primary 
>key), gives rise to conflicting requirements on the bean. What's the right approach?
>
> For example, I have parent entity Store with a StorePK consisting of storeNum field, 
>and corresponding getStoreNum() / setStoreNum() accessor methods. I also have a child 
>entity Receipt, with a ReceiptPK of (storeNum, receiptNum), so that receipts are 
>identified by store ((1,1), (1,2) for store #1, (2,1), (2,2) for store #2 and so on). 
>The corresponding methods on the ReceiptBean are getStoreNum() / setStoreNum() and 
>getReceiptNum() / setReceiptNum().
>
> Now, I want to define a bi-directional CMR between Store and Receipt, which means I 
>need a CMR method getStore() for ReceiptBean, returning a StoreLocal.
>
> Putting all this together, it seems the ReceiptBean must provide a getStore() and a 
>getStoreNum() method, both of which are implemented by the container. Ditto for the 
>setters. This seems horrible - there would be two columns in the underlying RDBMS 
>table. Also, it would seem that the onus is on the bean provider to keep these two 
>values in sync. In other words, if I create a new Receipt and in the ejbCreate() call 
>setStoreNum(), I would also need to do a lookup of StoreLocalHome.findByPrimaryKey() 
>to obtain the corresponding StoreLocal, and then call setStore().
>
> The alternative approach would be to define the ReceiptPK to contain a StoreLocal 
>reference, rather than a storeNumber value. Then, the methods would be the same and 
>would match. This doesn't make the ReceiptPK object transportable by a remote client, 
>however, so that feels wrong.  Indeed, the EJB spec insists (and the J2EE RI verifier 
>checks) that the PK must be a legal type for RMI-IIOP, so other than making the 
>StoreLocal reference transient, this looks like it isn't a goer.
>
> Any insights gratefully received...
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
>
>


--
_______________________________________________________________________________

Evan Ireland            Sybase EAServer Engineering         [EMAIL PROTECTED]
                           Wellington, New Zealand                +64 4 934-5856

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to