Hi,
Cool managed to solve the 1-1 relationship issue. I'm a happy camper for now
:)
Cheers
Nanik
----- Original Message -----
From: "Andrus Adamchik" <andru..bjectstyle.org>
To: <cayenne-use..bjectstyle.org>
Sent: Monday, March 10, 2003 9:28 PM
Subject: Re: 1-1 Relationship
> Nanik,
>
> for 1-1 to work properly, "toDepPk" must be set from a "detail" DbEntity
> to "master", since otherwise Cayenne can not tell which PK value is
> primary and which - dependent and should be resolved via a relationship.
> This can be done in the Modeler. In your case I guess Address is
> "master" and "city" is detail.
>
> Andrus
>
>
> Nanik Tolaram wrote:
>
> > Hi,
> >
> > I have a 1-1 relationship as follows in the datamap.map.xml (I know
> > the City and Address relationship doesn't make sense, but hey! this is
> > just for testing),
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <data-map project-version="1.0">
> > <db-entity name="ADDRESS">
> > <db-attribute name="address" type="CHAR" length="100"/>
> > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
> > isMandatory="true" length="11"/>
> > <db-attribute name="name" type="CHAR" length="100"/>
> > </db-entity>
> > <db-entity name="CITY">
> > <db-attribute name="CityID" type="INTEGER" isPrimaryKey="true"
> > isMandatory="true"/>
> > <db-attribute name="ID" type="INTEGER" isMandatory="true"/>
> > <db-attribute name="city" type="CHAR" length="100"/>
> > </db-entity>
> > <obj-entity name="Address" className="Address" dbEntityName="ADDRESS">
> > <obj-attribute name="address" type="java.lang.String"
> > db-attribute-name="address"/>
> > <obj-attribute name="name" type="java.lang.String"
> > db-attribute-name="name"/>
> > </obj-entity>
> > <obj-entity name="City" className="City" dbEntityName="CITY">
> > <obj-attribute name="city" type="java.lang.String"
> > db-attribute-name="city"/>
> > </obj-entity>
> > <db-relationship name="AddressCity" source="ADDRESS" target="CITY"
> > toDependentPK="false" toMany="false">
> > <db-attribute-pair source="id" target="ID"/>
> > </db-relationship>
> > <db-relationship name="RevAddressCity" source="CITY" target="ADDRESS"
> > toDependentPK="false" toMany="false">
> > <db-attribute-pair source="ID" target="id"/>
> > </db-relationship>
> > <obj-relationship name="AddressCity" source="Address" target="City"
> > toMany="false" deleteRule="Cascade">
> > <db-relationship-ref source="ADDRESS" target="CITY"
name="AddressCity"/>
> > </obj-relationship>
> > <obj-relationship name="RevAddressCity" source="City"
> > target="Address" toMany="false" deleteRule="Nullify">
> > <db-relationship-ref source="CITY" target="ADDRESS"
> > name="RevAddressCity"/>
> > </obj-relationship>
> > </data-map>
> >
> >
> > and the following code is used to store the data :
> >
> > ....
> > ....
> > ....
> >
> > DataContext ctxt = (DataContext)
> > request.getSession().getAttribute("context");
> >
> > Address anAddress= (Address)
> > ctxt.createAndRegisterNewObject("Address");
> > City aCity= (City) ctxt.createAndRegisterNewObject("City");
> >
> >
> > anAddress.setName(addressForm.getname());
> > anAddress.setAddress(addressForm.getaddress());
> >
> > aCity.setCity(addressForm.getcity());
> >
> > anAddress.setAddressCity(aCity);
> > ctxt.commitChanges(Level.WARN);
> >
> > ....
> > ....
> > ....
> >
> > It throws me an error,
> >
> > javax.servlet.ServletException: Some parts of PK are missing in
snapshot.
> > at
> >
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.
java:526)
> > at
> >
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:467)
> > at
> >
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
> > at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1409)
> > ..
> > ..
> > ..
> >
> >
> > root cause
> >
> > org.objectstyle.cayenne.CayenneRuntimeException: Some parts of PK are
> > missing in snapshot.
> > at
> >
org.objectstyle.cayenne.map.DbRelationship.srcFkSnapshotWithTargetSnapshot(D
bRelationship.java:251)
> > at
> >
org.objectstyle.cayenne.access.SnapshotManager.takeObjectSnapshot(SnapshotMa
nager.java:243)
> > at
> >
org.objectstyle.cayenne.access.DataContext.takeObjectSnapshot(DataContext.ja
va:304)
> > at
> >
org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:80
1)
> > at SaveAddressAction.execute(SaveAddressAction.java:48)
> > at
> >
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:465)
> > at
> >
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
> > at
> > org.apache.struts.action.ActionServlet.process(ActionServlet.java:1409)
> >
> > Any ideas ?
> >
> > Thanks
> > Nanik
> >
> >
>
This archive was generated by hypermail 2.0.0 : Mon Mar 10 2003 - 09:37:03 EST