Further testing reveled another issue performing updates.
If a child already exists on a parent and has a uuid then you add that child to a different parent it will not get saved in that new parent's collection. The child is updated by uuid and is not added to the new parent's collection. My child is mix:referenceable. Is the DefaultCollectionConverterImpl the correct collection converter to use? I have tried NTCollectionConverterImpl and it does appear to work correctly except the uuid's are different for the same child in each collection. (Maybe I'm not doing references correctly using collections?) The reason I'm trying to use the DefaultCollectionConverterImpl is it adds the additional property name in the path before the id field value, which is a 'soft' requirement for my organization. DefaultCollectionConverterImpl path example '/parent/children/child1' where children is the property name and child1 is the id. This is functionality I want. I don't want to rely on discriminators to figure out which node goes to which collection and it just seems wrong to not have that additional info in the path. NTCollectionConverterImpl path example '/parent /child1' where child1 is the id. Is there a way to get this behavior using NTCollectionConverterImpl? It would be nice if the jcrElementName was used in addition to the id when creating the path, such that '/parent/jcrElementName/id'. Pete From: Pete [mailto:[email protected]] Sent: Saturday, September 26, 2009 4:42 PM To: [email protected] Subject: OCM: Collection updates - path not consistent with inserts (id field) When an update is done on a collection, in my case adding new elements, the path naming is not consistent with inserts of new elements. The element path name should be the id field. I created a parent and added 2 children named 'child1' and 'child2' which have a property called 'name' annotated with '@Field(id = true)'. When inserted the children paths are: child1 path=/parent/children/child1 child2 path=/parent/children/child2 I then add 2 more children named 'child3' and 'child4' and do an update. Their paths are: child3 path=/parent/children/collection-element child4 path=/parent/children/collection-element[2] I believe the error is in the org.apache.jackrabbit.ocm.manager.collectionconverter.impl.DefaultCollectionConverterImpl. updateManagableCollection method. The code to determine the path name is different then what's used for inserts. Update code: elementJcrName = collectionDescriptor.getJcrElementName(); elementJcrName = (elementJcrName == null) ? COLLECTION_ELEMENT_NAME : elementJcrName; Insert code: // If the element object has a unique id => the element jcr node name = the id value if (elementClassDescriptor.hasIdField()){ String idFieldName = elementClassDescriptor.getIdFieldDescriptor().getFieldName(); elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString(); }else{ elementJcrName = collectionDescriptor.getJcrElementName(); if (elementJcrName == null){ // use PathFormat.checkFormat() here? elementJcrName = COLLECTION_ELEMENT_NAME; } } I have tested the change and it works properly. The path name for inserts and updates of newly created elements is consistent with the id field. I have never supplied a fix before but of course would be willing. I have a test case and the fix. I did attach my test and fix, but I'm not sure if attachments are allowed, if not I can send them to the appropriate persons. BTW I really like the OCM! Keep up the GREAT work! Peter Harootunian ------------------------------------------------------------------------------------------ Print out of the parent node and children: |---node, name=parent : path=/parent |---|---property, name=jcr:predecessors : value=} : path=/parent/jcr:predecessors |---|---property, name=jcr:uuid : value=[STRING ] - 2cb85e68-b49b-479f-8fec-006f4dc8c3ab : path=/parent/jcr:uuid |---|---property, name=jcr:mixinTypes : value=} : path=/parent/jcr:mixinTypes |---|---property, name=jcr:versionHistory : value=[REFERENCE] - a8abf6bf-46d2-43ff-b1dc-9f37b1ca8348 : path=/parent/jcr:versionHistory |---|---property, name=jcr:baseVersion : value=[REFERENCE] - 2da0279c-6478-499d-a004-b7d7a367b199 : path=/parent/jcr:baseVersion |---|---property, name=jcr:isCheckedOut : value=[BOOLEAN ] - true : path=/parent/jcr:isCheckedOut |---|---property, name=ocm_classname : value=[STRING ] - com.srcp.domain.model.OcmCollectionsTest$Parent : path=/parent/ocm_classname |---|---property, name=jcr:primaryType : value=[NAME ] - nt:unstructured : path=/parent/jcr:primaryType |---|---node, name=children : path=/parent/children |---|---|---property, name=jcr:primaryType : value=[NAME ] - nt:unstructured : path=/parent/children/jcr:primaryType |---|---|---node, name=child1 : path=/parent/children/child1 |---|---|---|---property, name=jcr:predecessors : value=} : path=/parent/children/child1/jcr:predecessors |---|---|---|---property, name=name : value=[STRING ] - child1 : path=/parent/children/child1/name |---|---|---|---property, name=jcr:uuid : value=[STRING ] - e49f8b4c-375a-4d06-b686-028520172ff6 : path=/parent/children/child1/jcr:uuid |---|---|---|---property, name=jcr:mixinTypes : value=} : path=/parent/children/child1/jcr:mixinTypes |---|---|---|---property, name=jcr:versionHistory : value=[REFERENCE] - 5beceaf0-b0af-4902-8942-32a9f66e5ba6 : path=/parent/children/child1/jcr:versionHistory |---|---|---|---property, name=jcr:baseVersion : value=[REFERENCE] - 310bdfd8-81e6-4a93-9a6f-f272f49c3aaf : path=/parent/children/child1/jcr:baseVersion |---|---|---|---property, name=jcr:primaryType : value=[NAME ] - nt:unstructured : path=/parent/children/child1/jcr:primaryType |---|---|---|---property, name=jcr:isCheckedOut : value=[BOOLEAN ] - true : path=/parent/children/child1/jcr:isCheckedOut |---|---|---|---property, name=ocm_classname : value=[STRING ] - com.srcp.domain.model.OcmCollectionsTest$Child : path=/parent/children/child1/ocm_classname |---|---|---node, name=child2 : path=/parent/children/child2 |---|---|---|---property, name=jcr:predecessors : value=} : path=/parent/children/child2/jcr:predecessors |---|---|---|---property, name=name : value=[STRING ] - child2 : path=/parent/children/child2/name |---|---|---|---property, name=jcr:uuid : value=[STRING ] - 2f11d28e-35f1-4936-bbd0-e3fa61956800 : path=/parent/children/child2/jcr:uuid |---|---|---|---property, name=jcr:mixinTypes : value=} : path=/parent/children/child2/jcr:mixinTypes |---|---|---|---property, name=jcr:versionHistory : value=[REFERENCE] - a61e266b-fcf3-4071-b666-ca4db4083142 : path=/parent/children/child2/jcr:versionHistory |---|---|---|---property, name=jcr:baseVersion : value=[REFERENCE] - c12db6cc-b3aa-4091-b134-c6ca32902ddd : path=/parent/children/child2/jcr:baseVersion |---|---|---|---property, name=jcr:primaryType : value=[NAME ] - nt:unstructured : path=/parent/children/child2/jcr:primaryType |---|---|---|---property, name=ocm_classname : value=[STRING ] - com.srcp.domain.model.OcmCollectionsTest$Child : path=/parent/children/child2/ocm_classname |---|---|---|---property, name=jcr:isCheckedOut : value=[BOOLEAN ] - true : path=/parent/children/child2/jcr:isCheckedOut |---|---|---node, name=collection-element : path=/parent/children/collection-element |---|---|---|---property, name=jcr:predecessors : value=} : path=/parent/children/collection-element/jcr:predecessors |---|---|---|---property, name=name : value=[STRING ] - child3 : path=/parent/children/collection-element/name |---|---|---|---property, name=jcr:uuid : value=[STRING ] - 62f4c459-355f-4103-8236-5cc300d85b45 : path=/parent/children/collection-element/jcr:uuid |---|---|---|---property, name=jcr:mixinTypes : value=} : path=/parent/children/collection-element/jcr:mixinTypes |---|---|---|---property, name=jcr:versionHistory : value=[REFERENCE] - 41ad9638-f517-4a08-812b-048d7555a3f5 : path=/parent/children/collection-element/jcr:versionHistory |---|---|---|---property, name=jcr:baseVersion : value=[REFERENCE] - 74628c94-cd5e-4e19-a83b-b22d33cec5e4 : path=/parent/children/collection-element/jcr:baseVersion |---|---|---|---property, name=ocm_classname : value=[STRING ] - com.srcp.domain.model.OcmCollectionsTest$Child : path=/parent/children/collection-element/ocm_classname |---|---|---|---property, name=jcr:primaryType : value=[NAME ] - nt:unstructured : path=/parent/children/collection-element/jcr:primaryType |---|---|---|---property, name=jcr:isCheckedOut : value=[BOOLEAN ] - true : path=/parent/children/collection-element/jcr:isCheckedOut |---|---|---node, name=collection-element : path=/parent/children/collection-element[2] |---|---|---|---property, name=jcr:predecessors : value=} : path=/parent/children/collection-element[2]/jcr:predecessors |---|---|---|---property, name=name : value=[STRING ] - child4 : path=/parent/children/collection-element[2]/name |---|---|---|---property, name=jcr:uuid : value=[STRING ] - 6dea91f2-a8e5-410f-8a9e-60f10328b16e : path=/parent/children/collection-element[2]/jcr:uuid |---|---|---|---property, name=jcr:mixinTypes : value=} : path=/parent/children/collection-element[2]/jcr:mixinTypes |---|---|---|---property, name=jcr:versionHistory : value=[REFERENCE] - af8d82da-234a-4bd5-b864-bef2032f9529 : path=/parent/children/collection-element[2]/jcr:versionHistory |---|---|---|---property, name=jcr:baseVersion : value=[REFERENCE] - 05c6a9f2-11ce-4319-a4a6-769efcee5806 : path=/parent/children/collection-element[2]/jcr:baseVersion |---|---|---|---property, name=ocm_classname : value=[STRING ] - com.srcp.domain.model.OcmCollectionsTest$Child : path=/parent/children/collection-element[2]/ocm_classname |---|---|---|---property, name=jcr:primaryType : value=[NAME ] - nt:unstructured : path=/parent/children/collection-element[2]/jcr:primaryType |---|---|---|---property, name=jcr:isCheckedOut : value=[BOOLEAN ] - true : path=/parent/children/collection-element[2]/jcr:isCheckedOut
