Help: Cannot set the read only flattened relationship x

From: Hill, Michael S CONT (michael.hil..avy.mil)
Date: Wed Jun 30 2004 - 11:20:13 EDT

  • Next message: Elia Morling: "Re: Working with Transient Objects"

    I know this subject has come up at least once before, but I can't seem to get this to work no matter how I try, and we are desperate to get his working ASAP, as the application of due this week. I have two dataobjects with a flattened relationship, and all I want to do is add and remove child objects. I know it can be done, as we have created the objects directly in the database and they show up in the application (after restarting it, of course...)

    project.addToPhases(exsitingPhase);

    Every time I try this I get:
    Caused by: org.objectstyle.cayenne.CayenneRuntimeException: [v.1.1M6 April 25 2004] Cannot set the read-only flattened relationship phases

    I don't want to directly add into the link table and refetch all of the objects. Is there a workaround that someone can point me to?

    Much thanks in advance,
    Mike.

    Relevant datamap.
    <db-entity name="phase" catalog="ttdb">
            <db-attribute name="active" type="TINYINT" isMandatory="true" length="1"/>
            <db-attribute name="description" type="VARCHAR" length="255"/>
            <db-attribute name="name" type="VARCHAR" isMandatory="true" length="15"/>
            <db-attribute name="pkey" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="11"/>
    </db-entity>
    <db-entity name="project" catalog="ttdb">
            <db-attribute name="active" type="TINYINT" isMandatory="true" length="1"/>
            <db-attribute name="description" type="VARCHAR" length="255"/>
            <db-attribute name="name" type="VARCHAR" isMandatory="true" length="15"/>
            <db-attribute name="pkey" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="11"/>
            <db-attribute name="team_id" type="INTEGER" isMandatory="true" length="11"/>
    </db-entity>
    <db-entity name="project_phase" catalog="ttdb">
            <db-attribute name="phase_id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="11"/>
            <db-attribute name="pkey" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="11"/>
            <db-attribute name="project_id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="11"/>
    </db-entity>

    <obj-entity name="Phase" className="timetracker3.datalayer.Phase" dbEntityName="phase">
            <obj-attribute name="active" type="java.lang.Byte" db-attribute-path="active"/>
            <obj-attribute name="description" type="java.lang.String" db-attribute-path="description"/>
            <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
    </obj-entity>
    <obj-entity name="Project" className="timetracker3.datalayer.Project" dbEntityName="project">
            <obj-attribute name="active" type="java.lang.Byte" db-attribute-path="active"/>
            <obj-attribute name="description" type="java.lang.String" db-attribute-path="description"/>
            <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
            <obj-attribute name="teamId" type="java.lang.Integer" db-attribute-path="team_id"/>
    </obj-entity>
    <obj-entity name="ProjectPhaseLink" className="timetracker3.datalayer.ProjectPhase" dbEntityName="project_phase">
    </obj-entity>

    <db-relationship name="phases" source="project_phase" target="phase" toDependentPK="false" toMany="true">
            <db-attribute-pair source="phase_id" target="pkey"/>
    </db-relationship>
    <db-relationship name="projects" source="project_phase" target="project" toDependentPK="false" toMany="true">
            <db-attribute-pair source="project_id" target="pkey"/>
    </db-relationship>
    <db-relationship name="phaseLink" source="project" target="project_phase" toDependentPK="false" toMany="true">
            <db-attribute-pair source="pkey" target="project_id"/>
    </db-relationship>
    <db-relationship name="projectLink" source="phase" target="project_phase" toDependentPK="false" toMany="true">
            <db-attribute-pair source="pkey" target="phase_id"/>
    </db-relationship>

    <obj-relationship name="phases" source="Project" target="Phase">
            <db-relationship-ref source="project" target="project_phase" name="phaseLink"/>
            <db-relationship-ref source="project_phase" target="phase" name="phases"/>
    </obj-relationship>
    <obj-relationship name="projects" source="Phase" target="Project">
            <db-relationship-ref source="phase" target="project_phase" name="projectLink"/>
            <db-relationship-ref source="project_phase" target="project" name="projects"/>
    </obj-relationship>

    Actual MySQL tables:
    CREATE TABLE `phase` (
      `active` tinyint(4) NOT NULL default '0',
      `description` varchar(255) default NULL,
      `name` varchar(25) NOT NULL default '',
      `pkey` int(11) NOT NULL default '0',
      PRIMARY KEY (`pkey`)
    ) TYPE=MyISAM;

    CREATE TABLE `project` (
      `active` tinyint(4) NOT NULL default '0',
      `description` varchar(255) default NULL,
      `name` varchar(15) NOT NULL default '',
      `pkey` int(11) NOT NULL default '0',
      `team_id` int(11) NOT NULL default '0',
      PRIMARY KEY (`pkey`)
    ) TYPE=MyISAM;

    CREATE TABLE `project_phase` (
      `phase_id` int(11) NOT NULL default '0',
      `project_id` int(11) NOT NULL default '0',
      `pkey` int(11) NOT NULL default '0',
      PRIMARY KEY (`pkey`)
    ) TYPE=MyISAM;



    This archive was generated by hypermail 2.0.0 : Wed Jun 30 2004 - 11:20:51 EDT