On 14 May 01, at 10:47, Richard Monson-Haefel wrote:

> Bi-directional relationships create some interesting situations, when
> concerned with establishing relationships between two participants.  The
> following scenario illustrates a problem that I would like vendors to
> comment on, if they are up for the challenge.

The MVCSoft Persistence Manager for JBoss is based on PFD1,
but the same referential integrity concerns exist in that version of
the spec.

>
> Assume that SalesRep has a one-to-many bidirectional relationship with
> Customer.
>
> ------------------
>
> SalesRep rep = SalesRepHome.findByPrimaryKey(somekey);
>
> Customer cust = CustomerHome.create( );
>
> cust.setSalesRep( rep);
>
> Colleciton colleciton = rep.getCustomers( );
>
> if(collection.contains( cust ))
>      flag = true;
> else
>     flag = false;
>
> -------------------
>
> What is the value of flag?  I suspect it should be true in this
> scenario.

I agree.

>
> However, what would happen if the Colleciton of Customer references was
> obtained before cust set rep in its salesRep relationship field?

Shouldn't matter.

>
> --------------------
>
> SalesRep rep = SalesRepHome.findByPrimaryKey(somekey);
>
> Colleciton colleciton = rep.getCustomers( );
>
> Customer cust = CustomerHome.create( );
>
> cust.setSalesRep( rep);
>
> if(collection.contains( cust ))
>      flag = true;
> else
>     flag = false;
>
> -------------------------
>
> In this case the flag should still be true, IMO, but it may not for some

I agree. This is how the MVCSoft Persistence Manager works.
Obviously the java.util.Collection needs to have some container
plumbing to manage this.

> containers.  The specification warns against modifying a Collection
> based relationship field when perusing a Interator of that Collection,
> but it doesn't, to my knowledge, address this situation.

Page 135 of EJB 2.0 PFD2 gives an example with a "side-effect"
referential integrity modification of an already-obtained collection.
(The "wrong way" to transfer the salesrep fails because the
collection is modified by a side effect during iteration.)

One-to-one bi-directional relationships are even more interesting: a
single operation can potentially have side effects in three other
objects.

-Dan


>
> Comments?
>
> Richard
>
> --
> Richard Monson-Haefel
> Author of Enterprise JavaBeans, 2nd Edition  (O'Reilly 2000)
> Co-Author of Java Message Service (O'Reilly 2000)
> http://www.jMiddleware.com
>
> ===========================================================================
> 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".
>

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