So I attached the mapping that I was talking about to CAY-1751. It works for me
on Derby. Here is the diff of changes to make the key propagate:
diff --git a/src/main/resources/FieldDomainMap.map.xml
b/src/main/resources/FieldDomainMap.map.xml
index e76fd96..530f8b2 100644
--- a/src/main/resources/FieldDomainMap.map.xml
+++ b/src/main/resources/FieldDomainMap.map.xml
@@ -14,7 +14,7 @@
</db-key-generator>
</db-entity>
<db-entity name="FRUIT_TREES">
- <db-attribute name="CODE_TYPE_TREE" type="NUMERIC"
isMandatory="true" length="3"/>
+ <db-attribute name="CODE_TYPE_TREE" type="NUMERIC"
isPrimaryKey="true" isMandatory="true" length="3"/>
<db-attribute name="ID_ENCLOSURE" type="NUMERIC"
isMandatory="true" length="12"/>
<db-attribute name="ID_FRUIT_TREES" type="NUMERIC"
isPrimaryKey="true" isMandatory="true" length="12"/>
<db-attribute name="PLANTING_DATE" type="DATE"
isMandatory="true"/>
@@ -24,7 +24,7 @@
</db-key-generator>
</db-entity>
<db-entity name="TREE_TYPES">
- <db-attribute name="CODE_TYPE_TREE" type="NUMERIC"
isMandatory="true" length="3"/>
+ <db-attribute name="CODE_TYPE_TREE" type="NUMERIC"
isPrimaryKey="true" isMandatory="true" length="3"/>
<db-attribute name="DESCRIPTION_TYPE_TREE" type="VARCHAR"
length="30"/>
<db-attribute name="ID_TREE_TYPE" type="NUMERIC"
isPrimaryKey="true" isMandatory="true" length="12"/>
<db-key-generator>
@@ -51,7 +51,7 @@
<db-relationship name="toTreeType" source="FRUIT_TREES"
target="TREE_TYPES" toMany="false">
<db-attribute-pair source="CODE_TYPE_TREE"
target="CODE_TYPE_TREE"/>
</db-relationship>
- <db-relationship name="toFruitTree" source="TREE_TYPES"
target="FRUIT_TREES" toMany="true">
+ <db-relationship name="toFruitTree" source="TREE_TYPES"
target="FRUIT_TREES" toDependentPK="true" toMany="true">
<db-attribute-pair source="CODE_TYPE_TREE"
target="CODE_TYPE_TREE"/>
</db-relationship>
<obj-relationship name="toFruitTree" source="Enclosure"
target="FruitTree" db-relationship-path="toFruitTree"/>
--
On Oct 23, 2012, at 7:50 PM, Felipe Martín Santos <[email protected]> wrote:
> Ok Andrus, I've discovered how attach files...
>
> When you have a free moment, check it out please, if you have troubles
> understanding something... ask me!!
>
> Best regards!!
>
> 2012/10/23 Felipe Martín Santos <[email protected]>
>
>> Muchísimas gracias Andrus!!
>>
>> I've created https://issues.apache.org/jira/browse/CAY-1751
>>
>> is possible upload a file? or I must write the code in the Description
>> Frame??
>>
>>
>>
>>
>> 2012/10/23 Andrus Adamchik <[email protected]>
>>
>>>> Andrus, you can test this probleme if you have a similar example (more
>>> or
>>>> less), and check what I say.
>>>
>>>
>>> Yes, if you can provide a mapping project demonstrating an issue (no need
>>> for Java classes), I'll take a look. Feel free to use our Jira for that:
>>>
>>> https://issues.apache.org/jira/browse/CAY
>>>
>>> Andrus
>>>
>>>
>>> On Oct 23, 2012, at 2:57 PM, Felipe Martín Santos <[email protected]>
>>> wrote:
>>>
>>>> Sorry but doesn' work :-(
>>>>
>>>> MY RELATIONSHIPS:
>>>>
>>>> <db-relationship name="toUse" source="ENCLOSURE" target="USE"
>>>> toMany="false">
>>>> <db-attribute-pair source="CD_USE" target="CD_USE"/>
>>>> </db-relationship>
>>>>
>>>> <db-relationship name="toPieceOfGround" source="ENCLOSURE"
>>>> target="PIECE_OF_GROUND" toMany="false">
>>>> db-attribute-pair source="ID_PIECE_OF_GROUND"
>>> target="ID_PIECE_OF_GROUND"/>
>>>> </db-relationship>
>>>>
>>>> <obj-relationship name="toPieceOfGround" source="Enclosure"
>>>> target="PieceOfGround" deleteRule="Nullify"
>>>> db-relationship-path="toPieceOfGround"/>
>>>>
>>>> <obj-relationship name="toUse" source="Enclosure" target="Use"
>>>> deleteRule="Nullify" db-relationship-path="toUse"/>
>>>>
>>>> *********************************************
>>>> THE CODE FOR INSERT (We use Generic Persistent Class of Cayenne)
>>>>
>>>> Expression exp = ExpressionFactory.matchExp("idPieceOfGround",
>>> "123673");
>>>> SelectQuery query = new SelectQuery("PieceOfGround", exp);
>>>> List<DataObject> pieceOfGround = context.performQuery(query);
>>>>
>>>> exp = ExpressionFactory.matchExp("cdUse", 5990403);
>>>> query = new SelectQuery("Use", exp);
>>>> List<DataObject> use = context.performQuery(query);
>>>>
>>>> DataObject enclosure = new CayenneDataObject();
>>>> enclosure.setObjectId(new ObjectId("Enclosure"));
>>>>
>>>> // Set de DataObject for the relationships
>>>> enclosure.writeProperty("toPieceOfGround", pieceOfGround.get(0));
>>>> enclosure.writeProperty("toUse", use.get(0));
>>>>
>>>> context.registerNewObject(arbol);
>>>> context.commitChanges();
>>>>
>>>> *************************************
>>>> MY CONCLUSIONS
>>>>
>>>> cayenne context.commitChanges() builds automatically the insert:
>>>>
>>>> * ID_PIECE_OF_GROUND is pk in PIECE_OF_GROUND: when I do
>>>> enclosure.writeProperty("toPieceOfGround", pieceOfGround.get(0)), in the
>>>> commit moment, cayenne can extract automatically the ID_PIECE_OF_GROUND
>>> for
>>>> the pieceOfGround DataObject, and put this value as insert parameter.
>>>>
>>>> * CD_USE is NOT pk in USE: when I do enclosure.writeProperty("toUse",
>>>> use.get(0)), in the commit moment, cayenne CAN´T extract automatically
>>> the
>>>> CD_USE for the use DataObject, and can´t put this value as insert
>>> parameter.
>>>>
>>>> I think the problem is that, "a bug" or a cayenne design issue not
>>> taken.
>>>>
>>>>
>>> ****************************************************************************
>>>>
>>>> In the db-entity PIECE_OF_GROUND I can't put
>>>> <db-attribute name="CD_USE" type="VARCHAR" isMandatory="true"
>>> length="2">
>>>> as PK, because its PK is ID_PIECE_GROUND (Autogenerated by cayenne with
>>> an
>>>> Oracle sequence) and if I include CD_USE as PK cayenne fails
>>>> (org.apache.cayenne.CayenneRuntimeException: [v.3.0.2 Jun 11 2011
>>> 09:26:09]
>>>> Primary Key autogeneration only works for a single attribute.).
>>>>
>>>> I've tried all the possible combinations tha you've said me, but none
>>> works
>>>> :-)
>>>>
>>>> Andrus, you can test this probleme if you have a similar example (more
>>> or
>>>> less), and check what I say.
>>>>
>>>> Thank you very much for your attention!!
>>>
>>>
>>