Hi Erik,With bidirectional relationships (defined in the jdo metadata via the mapped-by attribute in field or property), there are several issues:
1. Is it necessary to set both sides of the relationship in order for the relationship to be instantiated in the datastore?
No. Only one side of the relationship needs to be set in order to set or update the relationship in the datastore.
2. If only one side is set by the application, is the other side set immediately by the JDO implementation?
No. The specification doesn't disallow it, but it doesn't require it either. It is required to be set only after a flush or commit operation.
3. Is it permitted to set both sides of the relationship?Yes, the application is permitted to set both sides of the relationship. This is done below in several places.
4. If both sides are set, and they disagree, what happens?At commit or flush time, an exception is thrown by the JDO implementation.
Hope that elaboration helps, Craig On Apr 7, 2006, at 8:33 AM, Erik Bengtson wrote:
Hi,According JDO, is it necessary to set the value of a 1-1 bidirectional on bothvalues? 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);
Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp!
smime.p7s
Description: S/MIME cryptographic signature
