cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felipe Martín Santos <gadita...@gmail.com>
Subject Re: Possible bug in cayene 3.0.2 to set relationships???
Date Tue, 23 Oct 2012 11:57:50 GMT
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!!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message