FAQ
I just spent a couple hours debugging an issue where the model was messed
up and the to-many checkbox (in the DbEntity editors) was set on both sides
of a relationship and Cayenne was inserting NULLs for the FK and orphaning
records. Should Cayenne Modeler give a warning when both sides are to-many
(and not a flattened many-to-many)?

Here is the XML for the issue (using 3.1B2, but the issue exists in 3.0.2
also):

~> cat cayenne-project.xml
<?xml version="1.0" encoding="utf-8"?>
<domain project-version="6">
<map name="datamap"/>
</domain>


~> cat datamap.map.xml
<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
http://cayenne.apache.org/schema/3.0/modelMap.xsd"
  project-version="6">
<db-entity name="child">
<db-attribute name="parent_fk" type="BIGINT"/>
  <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
isMandatory="true"/>
</db-entity>
  <db-entity name="parent">
<db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
isMandatory="true"/>
  </db-entity>
<db-relationship name="to_parent" source="child" target="parent"
toMany="true">
  <db-attribute-pair source="parent_fk" target="pk"/>
</db-relationship>
  <db-relationship name="to_child" source="parent" target="child"
toMany="true">
<db-attribute-pair source="pk" target="parent_fk"/>
  </db-relationship>
</data-map>


Thanks,

mrg

Search Discussions

  • Andrus Adamchik at Nov 14, 2013 at 7:48 am

    Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?
    I think it should.

    A.
    On Nov 13, 2013, at 8:20 PM, Michael Gentry wrote:

    I just spent a couple hours debugging an issue where the model was messed
    up and the to-many checkbox (in the DbEntity editors) was set on both sides
    of a relationship and Cayenne was inserting NULLs for the FK and orphaning
    records. Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?

    Here is the XML for the issue (using 3.1B2, but the issue exists in 3.0.2
    also):

    ~> cat cayenne-project.xml
    <?xml version="1.0" encoding="utf-8"?>
    <domain project-version="6">
    <map name="datamap"/>
    </domain>


    ~> cat datamap.map.xml
    <?xml version="1.0" encoding="utf-8"?>
    <data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
    http://cayenne.apache.org/schema/3.0/modelMap.xsd"
    project-version="6">
    <db-entity name="child">
    <db-attribute name="parent_fk" type="BIGINT"/>
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-entity name="parent">
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-relationship name="to_parent" source="child" target="parent"
    toMany="true">
    <db-attribute-pair source="parent_fk" target="pk"/>
    </db-relationship>
    <db-relationship name="to_child" source="parent" target="child"
    toMany="true">
    <db-attribute-pair source="pk" target="parent_fk"/>
    </db-relationship>
    </data-map>


    Thanks,

    mrg
  • Michael Gentry at Nov 14, 2013 at 2:32 pm
    I'll create a JIRA for it later. I think it should also include a warning
    to check for to-one in both directions, also (unless To-Dep is checked).

    On Thu, Nov 14, 2013 at 2:47 AM, Andrus Adamchik wrote:

    Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?
    I think it should.

    A.
    On Nov 13, 2013, at 8:20 PM, Michael Gentry wrote:

    I just spent a couple hours debugging an issue where the model was messed
    up and the to-many checkbox (in the DbEntity editors) was set on both sides
    of a relationship and Cayenne was inserting NULLs for the FK and orphaning
    records. Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?

    Here is the XML for the issue (using 3.1B2, but the issue exists in 3.0.2
    also):

    ~> cat cayenne-project.xml
    <?xml version="1.0" encoding="utf-8"?>
    <domain project-version="6">
    <map name="datamap"/>
    </domain>


    ~> cat datamap.map.xml
    <?xml version="1.0" encoding="utf-8"?>
    <data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
    http://cayenne.apache.org/schema/3.0/modelMap.xsd"
    project-version="6">
    <db-entity name="child">
    <db-attribute name="parent_fk" type="BIGINT"/>
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-entity name="parent">
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-relationship name="to_parent" source="child" target="parent"
    toMany="true">
    <db-attribute-pair source="parent_fk" target="pk"/>
    </db-relationship>
    <db-relationship name="to_child" source="parent" target="child"
    toMany="true">
    <db-attribute-pair source="pk" target="parent_fk"/>
    </db-relationship>
    </data-map>


    Thanks,

    mrg
  • John Huss at Nov 14, 2013 at 2:37 pm
    Can you also check that the Fk and Pk columns are the same type? MySQL
    requires this and if you mismatch Integer and BigInt it doesn't work.

    John
    On Thursday, November 14, 2013, Michael Gentry wrote:

    I'll create a JIRA for it later. I think it should also include a warning
    to check for to-one in both directions, also (unless To-Dep is checked).


    On Thu, Nov 14, 2013 at 2:47 AM, Andrus Adamchik <andrus@objectstyle.org<javascript:;>
    wrote:
    Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?
    I think it should.

    A.
    On Nov 13, 2013, at 8:20 PM, Michael Gentry wrote:

    I just spent a couple hours debugging an issue where the model was
    messed
    up and the to-many checkbox (in the DbEntity editors) was set on both sides
    of a relationship and Cayenne was inserting NULLs for the FK and orphaning
    records. Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?

    Here is the XML for the issue (using 3.1B2, but the issue exists in
    3.0.2
    also):

    ~> cat cayenne-project.xml
    <?xml version="1.0" encoding="utf-8"?>
    <domain project-version="6">
    <map name="datamap"/>
    </domain>


    ~> cat datamap.map.xml
    <?xml version="1.0" encoding="utf-8"?>
    <data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
    http://cayenne.apache.org/schema/3.0/modelMap.xsd"
    project-version="6">
    <db-entity name="child">
    <db-attribute name="parent_fk" type="BIGINT"/>
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-entity name="parent">
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-relationship name="to_parent" source="child" target="parent"
    toMany="true">
    <db-attribute-pair source="parent_fk" target="pk"/>
    </db-relationship>
    <db-relationship name="to_child" source="parent" target="child"
    toMany="true">
    <db-attribute-pair source="pk" target="parent_fk"/>
    </db-relationship>
    </data-map>


    Thanks,

    mrg
  • Michael Gentry at Nov 14, 2013 at 4:40 pm
    Sounds like a good idea. I'll probably create separate JIRAs for them now.

    Thanks,

    mrg

    On Nov 14, 2013, at 9:37 AM, John Huss wrote:

    Can you also check that the Fk and Pk columns are the same type? MySQL
    requires this and if you mismatch Integer and BigInt it doesn't work.

    John
    On Thursday, November 14, 2013, Michael Gentry wrote:

    I'll create a JIRA for it later. I think it should also include a warning
    to check for to-one in both directions, also (unless To-Dep is checked).


    On Thu, Nov 14, 2013 at 2:47 AM, Andrus Adamchik <andrus@objectstyle.org<javascript:;>
    wrote:
    Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?
    I think it should.

    A.

    On Nov 13, 2013, at 8:20 PM, Michael Gentry <mgentry@masslight.net<javascript:;>>
    wrote:
    I just spent a couple hours debugging an issue where the model was
    messed
    up and the to-many checkbox (in the DbEntity editors) was set on both sides
    of a relationship and Cayenne was inserting NULLs for the FK and orphaning
    records. Should Cayenne Modeler give a warning when both sides are to-many
    (and not a flattened many-to-many)?

    Here is the XML for the issue (using 3.1B2, but the issue exists in
    3.0.2
    also):

    ~> cat cayenne-project.xml
    <?xml version="1.0" encoding="utf-8"?>
    <domain project-version="6">
    <map name="datamap"/>
    </domain>


    ~> cat datamap.map.xml
    <?xml version="1.0" encoding="utf-8"?>
    <data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
    http://cayenne.apache.org/schema/3.0/modelMap.xsd"
    project-version="6">
    <db-entity name="child">
    <db-attribute name="parent_fk" type="BIGINT"/>
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-entity name="parent">
    <db-attribute name="pk" type="BIGINT" isPrimaryKey="true"
    isMandatory="true"/>
    </db-entity>
    <db-relationship name="to_parent" source="child" target="parent"
    toMany="true">
    <db-attribute-pair source="parent_fk" target="pk"/>
    </db-relationship>
    <db-relationship name="to_child" source="parent" target="child"
    toMany="true">
    <db-attribute-pair source="pk" target="parent_fk"/>
    </db-relationship>
    </data-map>


    Thanks,

    mrg

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categoriescayenne
postedNov 13, '13 at 5:21p
activeNov 14, '13 at 4:40p
posts5
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase