0

我是 Apache Cayenne 的新手。

我只有一个实体,称为产品。这个实体与自身是多对多的关系,即一个产品可以包含产品,也可以被其他产品包含。

我无法用 Cayenne 建模这种关系。我要做的是: 1) 我创建一个名为 Composition 的表,其中包含两个字段,即 PK 和 FK。2) 我创建了两个从 Product 到 Composition 的 toMany(一个从 product.id 到 Composition.contained_id,一个从 product.id 到 Composition.base_id) 这应该与 DB 一起使用 现在我只创建一个 ObjEntity:Product。但是.. 我怎样才能建立一个扁平的关系?我正在关注这个:http ://cayenne.apache.org/doc/cayennemodeler-flattened-relationships.html但可能是因为它与自身的关系我无法在“目标”组合框中选择实体..

谢谢弗朗西斯科

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

4

1 回答 1

1

当您选择第一个关系时,“目标”组合为空,仅仅是因为连接表没有 ObjEntity。但是,如果您继续选择下一个路径组件,“产品”将出现在组合框中。我希望我们重新设计这个 UI 以获得更好的清晰度,但它现在仍然有效。请参阅下面的 DataMap XML 示例。我刚刚用 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>
于 2012-03-08T00:55:11.280 回答