----- Original Message -----
From: "Hemant Khandelwal" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, May 14, 2001 10:42 PM
Subject: Re: EJB 2.0: Bi-Directional Relationships
Hi Richard,
Please refer to section 10.3.6.2 of PFD2 for EJB2.0.
These lines are my favourite - as far as relationship is concerned - as an
EJB Server Vendor.
"The semantics of a set accessor method, when applied to a collection-valued
cmr-field, is also determined by the referential integrity semantics
associated with the multiplicity of the relationship. The identity of the
collection object referenced by a cmr-field does not change when a set
accessor method is executed."
So when a set method is executed, irrespective of when the collection was
first obtained, it will always be updated by the container to maintain the
integrity and validity of the relationship at the Object level. This is
possible because implementataion of both Collection and set<METHOD> for
cmr-fields is provided by the container.
Regards,
Hemant
Server Team,
Pramati Technologies
www.pramati.com
----- Original Message -----
From: "Richard Monson-Haefel" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 14, 2001 9:17 PM
Subject: EJB 2.0: Bi-Directional Relationships
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.
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.
However, what would happen if the Colleciton of Customer references was
obtained before cust set rep in its salesRep relationship field?
--------------------
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
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.
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".