1-1 Relationship

From: Nanik Tolaram (nanikjav..otmail.com)
Date: Mon Mar 10 2003 - 02:54:20 EST

  • Next message: Andrus Adamchik: "Re: 1-1 Relationship"

    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(RequestProcessor.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(DbRelationship.java:251)
     at org.objectstyle.cayenne.access.SnapshotManager.takeObjectSnapshot(SnapshotManager.java:243)
     at org.objectstyle.cayenne.access.DataContext.takeObjectSnapshot(DataContext.java:304)
     at org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:801)
     at SaveAddressAction.execute(SaveAddressAction.java:48)
     at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.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 - 02:58:13 EST