Hi, yeah, I need to find some spare time to review it.
Andrus On Oct 31, 2012, at 12:59 PM, Felipe Martín Santos <[email protected]> wrote: > Good Morning Andrus!! > > I've reopened the thread > https://issues.apache.org/jira/browse/CAY-1751because now the problem > is when I try to get one record (inserted > previously)... I test and <ObjectId:TreeType, CODE_TYPE_TREE=1> is in > database. > > Perhaps this is a foreign key (unique) bug?? > > Thank you for your answer. > > Best Regards!! > > > > 2012/10/29 Felipe Martín Santos <[email protected]> > >> Ok, I've tested with both: the proposed example and my real code... Now I >> can insert records in the database. :-) Thank you very very very much.... >> >> But now I've a problem when I get a FruiTree Object from the database. If >> I navigate to Enclosure.... There's not a problem, but when I navigate to >> TreeTypes.... ERROR oooooops!! >> >> Here the code!! >> >> SelectQuery treeQuery = new SelectQuery("FruitTree"); >> List<DataObject> trees = context.performQuery(treeQuery); >> >> DataObject tree = trees.get(0); >> >> DataObject enclosure = (DataObject)tree.readProperty("toEnclosure"); >> Object description = enclosure.readProperty("descriptionEnclosure"); >> >> DataObject treeType = (DataObject)tree.readProperty("toTreeType"); >> *Object codeTreeType = treeType.readProperty("codeTypeTree");* // here >> comes the error >> Object descriptionTreeType = treeType.readProperty("descriptionTypeTree"); >> >> >> *org.apache.cayenne.FaultFailureException: [v.3.0.2 Jun 11 2011 09:26:09] >> Error resolving fault for ObjectId: <ObjectId:TreeType, CODE_TYPE_TREE=1> >> and state (hollow). Possible cause - matching row is missing from the >> database. >> at >> org.apache.cayenne.BaseContext.prepareForAccess(BaseContext.java:171) >> at >> org.apache.cayenne.CayenneDataObject.readProperty(CayenneDataObject.java:219) >> at >> org.apache.cayenne.CayenneDataObject.readSimpleProperty(CayenneDataObject.java:203) >> at >> org.apache.cayenne.CayenneDataObject.readNestedProperty(CayenneDataObject.java:132) >> at >> org.apache.cayenne.CayenneDataObject.readNestedProperty(CayenneDataObject.java:154) >> at >> es.juntadeandalucia.agapa.gis.ide.dataset.sigpac.test.FruitTest.test(FruitTest.java:150) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) >> at java.lang.reflect.Method.invoke(Method.java:597) >> at >> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) >> at >> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) >> at >> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) >> at >> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) >> at >> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) >> at >> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) >> at >> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) >> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) >> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) >> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) >> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) >> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) >> at org.junit.runners.ParentRunner.run(ParentRunner.java:236) >> at >> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) >> at >> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) >> at >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) >> at >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) >> at >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) >> at >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) >> >> >> * >> >> 2012/10/25 Andrus Adamchik <[email protected]> >> >>> 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!! >>>>>> >>>>>> >>>>> >>> >>> >>
