You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Christophe Lombart (JIRA)" <ji...@apache.org> on 2008/04/21 23:53:21 UTC

[jira] Resolved: (JCR-1325) Problems mapping custom collections

     [ https://issues.apache.org/jira/browse/JCR-1325?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christophe Lombart resolved JCR-1325.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.5

Fixed. 
I also reviewed the support for Collection & Map. The mapping definition can be simplified with parameterized classes. In this case the elementClassName setting is not necessary. There is a exemple in the unit tests (see the class org.apache.jackrabbit.ocm.testmodel.collection.Main). 

Major interfaces and classes are supported (Collection, List, ArrayList, Vector,Map, HashMap, ...) without creating extra code. 

In summary, there are3 different ways to define a collection or a Map : 

1. With a parameterized class, it is not necessary to specify the elementClassName

   @Collection private List<Element> list;

2. Without specifying the element type: in this case, this is mandatory to define the elementClassName

   @Collection (elementClassName=MyContent.class)
    private List list;

3. Create a descendant of ManageableCollection & ManageableMap for complex collections or maps. elementClassName is still mandatory if the descendant is not parameterized. 




> Problems mapping custom collections
> -----------------------------------
>
>                 Key: JCR-1325
>                 URL: https://issues.apache.org/jira/browse/JCR-1325
>             Project: Jackrabbit
>          Issue Type: Bug
>          Components: jackrabbit-ocm
>    Affects Versions: 1.4
>            Reporter: Sebastian Gomez
>            Assignee: Christophe Lombart
>             Fix For: 1.5
>
>         Attachments: ManageableCollectionUtil.java.patch
>
>
> When using a custom list that extends from java.util.AbstractList, ManageableCollectionUtil.getManageableCollection raises a JcrMappingException because it does not consider the custom list to be a java.util.List. This is because it uses "if (object.getClass().equals(List.class))" instead of "if (object instanceof List)". The same thing will probably happen when using a custom Collection, a custom ArrayList, etc. This is the stack trace:
> org.apache.jackrabbit.ocm.exception.JcrMappingException: Unsupported collection 
> type : *********** (MyCustomList class) 
>         at org.apache.jackrabbit.ocm.manager.collectionconverter.ManageableColle 
> ctionUtil.getManageableCollection(ManageableCollectionUtil.java:153) 
>         at org.apache.jackrabbit.ocm.manager.objectconverter.impl.ObjectConverte 
> rImpl.insertCollectionFields(ObjectConverterImpl.java:780) 
>         at org.apache.jackrabbit.ocm.manager.objectconverter.impl.ObjectConverte 
> rImpl.insert(ObjectConverterImpl.java:221) 
>         at org.apache.jackrabbit.ocm.manager.objectconverter.impl.ObjectConverte 
> rImpl.insert(ObjectConverterImpl.java:146) 
>         at org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl.inser 
> t(ObjectContentManagerImpl.java:407) 
> I have come up to this bug using a MyCustomList<MyClass>, with MyCustomList extending java.util.AbstractList<MyClass>.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.