db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Bouschen <mbo.t...@spree.de>
Subject Re: TCK company model and managed associations
Date Fri, 07 Apr 2006 17:03:07 GMT
Erik Bengtson wrote:

> Hi,
> 
> According JDO, is it necessary to set the value of a 1-1 bidirectional on both
> values?

It depends whether you want to see the other side being changed in the 
same transaction. On flush the change gets flushed no matter which side 
of the relationship has been changed. So in the next transaction you see 
  the change on both sides of the relationship. But there is no 
requirement to update the other side in memory before flush.

Here is the part of the spec I think is relevant. It is in section "15.3 
Relationship Mapping" on page 187:

Regardless of which side changes the relationship, flush (whether done 
as part of commit or explicitly by the user) will modify the datastore 
to reflect the change and will update the memory model for consistency. 
There is no further behavior implied by having both sides of the 
relationship map to the same database column(s). In particular, making a 
change to one side of the relationship does not imply any runtime 
behavior by the JDO implementation to change the other side of the 
relationship in memory prior to flush, and there is no requirement to 
load fields affected by the change if they are not already loaded.

Hope this answers the question.

Regards Michael

> 
> Thanks,
> 
> ICompany com = (ICompany) pm.newInstance(ICompany.class);
> com.setCompanyid(1);
> com.setName("c1");
> 
> IAddress address = (IAddress) pm.newInstance(IAddress.class);
> address.setAddrid(1);
> com.setAddress(address);
> 
> HashSet setDept = new HashSet();
> com.setDepartments(setDept);
> 
> IDepartment dept = (IDepartment) pm.newInstance(IDepartment.class);
> setDept.add(dept);
> dept.setDeptid(1);
> 
> HashSet set1 = new HashSet();
> dept.setEmployees(set1);
> 
> IPartTimeEmployee p1 = (IPartTimeEmployee)
> pm.newInstance(IPartTimeEmployee.class);
> p1.setPersonid(1);
> p1.setBirthdate(new Date());
> p1.setFirstname("p1");
> set1.add(p1);
> 
> IFullTimeEmployee p2 = (IFullTimeEmployee)
> pm.newInstance(IFullTimeEmployee.class);
> p2.setPersonid(2);
> p2.setBirthdate(new Date());
> p2.setFirstname("p2");
> p2.setSalary(2);
> 
> IDentalInsurance di1 = (IDentalInsurance)
> pm.newInstance(IDentalInsurance.class);
> di1.setInsid(1);
> di1.setCarrier("Carrier");
> di1.setEmployee(p2); // <----not managed relation? ##############
> p2.setDentalInsurance(di1);
> set1.add(p2);


-- 
Michael Bouschen		Tech@Spree Engineering GmbH
mailto:mbo.tech@spree.de	http://www.tech.spree.de/
Tel.:++49/30/235 520-33		Buelowstr. 66			
Fax.:++49/30/2175 2012		D-10783 Berlin			

Mime
View raw message