0

私はApacheCayenneを初めて使用します。

Productというエンティティが1つだけあります。このエンティティは、それ自体と多対多の関係を持っています。つまり、製品には製品を含めることができ、他の製品に含めることができます。

カイエンとのこの関係をモデル化することはできません。私がしていることは次のとおりです。1)PKとFKの両方である2つのフィールドを持つCompositionというテーブルを作成します。2)ProductからCompositionまで2つのtoManyを作成します(1つはproduct.idからComposition.contained_idまで、もう1つはproduct.idからComposition.base_idまで)これはDBで機能するはずです。これで、1つのObjEntity:Productのみを作成します。しかし..どうすればフラットな関係を作成できますか?私はこれをフォローしています:http ://cayenne.apache.org/doc/cayennemodeler-flattened-relationships.htmlしかし、それ自体との関係であるためか、「ターゲット」コンボボックスでエンティティを選択できません。

ありがとうフランチェスコ

編集:2つのエンティティが異なる場合にも、ターゲットチェックボックスの問題があります。カイエンモデラーv.3.0.2

4

1 に答える 1

1

結合テーブルにObjEntityがないという理由だけで、最初の関係を選択すると、「ターゲット」コンボは空になります。ただし、次のパスコンポーネントを選択し続けると、コンボボックスに「製品」が表示されます。わかりやすくするためにこのUIを再設計したいのですが、今でも機能します。以下のDataMapXMLサンプルを参照してください。3.0.2Modelerで作成しました。

お役に立てれば。

<?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 に答える