Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Apache多对多关系_Java_Apache Cayenne - Fatal编程技术网

Java Apache多对多关系

Java Apache多对多关系,java,apache-cayenne,Java,Apache Cayenne,我是Apache Cayenne的新手 我只有一个实体,叫做产品。 该实体与自身有多对多关系,即产品可以包含产品,也可以被其他产品包含 我无法模拟与Cayenne的这种关系。。 我所做的是: 1) 我创建了一个名为Composition的表,其中有两个字段,它们都是PKs和FKs。 2) 我创建了两个从Product到Composition的toMany(一个从Product.id到Composition.contained\u id,一个从Product.id到Composition.base

我是Apache Cayenne的新手

我只有一个实体,叫做产品。 该实体与自身有多对多关系,即产品可以包含产品,也可以被其他产品包含

我无法模拟与Cayenne的这种关系。。 我所做的是: 1) 我创建了一个名为Composition的表,其中有两个字段,它们都是PKs和FKs。 2) 我创建了两个从Product到Composition的toMany(一个从Product.id到Composition.contained\u id,一个从Product.id到Composition.base\u id) 这应该适用于DB 现在我只创建一个对象:产品。 但是我如何才能建立扁平化的关系??我遵循这一点:但可能因为它本身就是一种关系,所以我无法在“目标”组合框中选择一个实体

多谢各位 弗朗西斯科

编辑:如果两个实体不同,也会出现目标复选框问题。Cayenne Modeler v.3.0.2

选择第一个关系时,“目标”组合为空,原因很简单,因为联接表没有对象。但是如果您继续选择下一个路径组件,“产品”将出现在组合框中。我希望我们重新设计这个用户界面以获得更好的清晰度,但它现在仍然可以工作。请参见下面的DataMapXML示例。我刚刚用3.0.2 Modeler创建了它

希望这有帮助

<?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="3.0.0.1">
    <db-entity name="composition">
        <db-attribute name="BASE_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
        <db-attribute name="CONTAINED_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
    </db-entity>
    <db-entity name="product">
        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
        <db-attribute name="NAME" type="VARCHAR" length="255"/>
    </db-entity>
    <obj-entity name="Product" dbEntityName="product">
        <obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
    </obj-entity>
    <db-relationship name="base" source="composition" target="product" toMany="false">
        <db-attribute-pair source="BASE_ID" target="ID"/>
    </db-relationship>
    <db-relationship name="contained" source="composition" target="product" toMany="false">
        <db-attribute-pair source="CONTAINED_ID" target="ID"/>
    </db-relationship>
    <db-relationship name="base" source="product" target="composition" toDependentPK="true" toMany="true">
        <db-attribute-pair source="ID" target="BASE_ID"/>
    </db-relationship>
    <db-relationship name="contained" source="product" target="composition" toDependentPK="true" toMany="true">
        <db-attribute-pair source="ID" target="CONTAINED_ID"/>
    </db-relationship>
    <obj-relationship name="base" source="Product" target="Product" deleteRule="Deny" db-relationship-path="contained.base"/>
    <obj-relationship name="contained" source="Product" target="Product" deleteRule="Deny" db-relationship-path="base.contained"/>
</data-map>