Hello,

there are the defnitions of the tagnames missing in your binding.

You may try this one:

<mapping name="group" class="com.bv.core.domain.impl.ContentItemGroupDefault" 
  extends="com.ited.domain.impl.EntityDao" post-set="postSet" ordered="false">

  <collection field="childGroups" 
item-type="com.bv.core.domain.ContentItemGroup" 
     create-type="java.util.HashSet">

    <structure name="group">
      <collection field="contentItems" 
item-type="com.bv.core.domain.ContentItem" 
         create-type="java.util.HashSet">

         <structure name="item"/>
      </collection>
    </structure>
  </collection>
</mapping>


Greetings,

Marko Voß
ePublishing & eScience
Development & Applied Research
Phone +49 7247 808-744
Fax +49 7247 808-133
[email protected]


FIZ Karlsruhe - Leibniz Institute for Information Infrastructure
Hermann-von-Helmholtz-Platz 1
76344 Eggenstein-Leopoldshafen, Germany

www.fiz-karlsruhe.de


-----Original Message-----
From: Ed Bras [mailto:[email protected]] 
Sent: Friday, March 25, 2011 4:55 PM
To: 'JiBX users'
Subject: [jibx-users] jibx determines wrong mapping ?

Jibx seems to take the wrong mapping definitions when mapping a collection,
that results in a ClassCastException.

I have the following piece of xml:
----
<group key='keyG1'>
  <item key='keyG1I1'>
   <value>keyG1I1V</value>
  </item>
</group>

<group key='keyG2'>
  <group key='keyG2.1'>
    <item key='keyG2.1I1'>
      <value>keyG2.1I1V</value>
    </item>
  </group>
</group>                        
---

And the mapping snippet looks like this:
----
<mapping name="group"
class="com.bv.core.domain.impl.ContentItemGroupDefault"
extends="com.ited.domain.impl.EntityDao" 
    post-set="postSet" ordered="false">
 <collection field="childGroups" usage="optional"
item-type="com.bv.core.domain.ContentItemGroup" 
                 create-type="java.util.HashSet" />
 <collection field="contentItems" usage="optional"
item-type="com.bv.core.domain.ContentItem" 
                 create-type="java.util.HashSet" />
</mapping>

<mapping name="item" class="com.bv.core.domain.impl.ContentItemDefault"
extends="com.ited.domain.impl.EntityNameKeyValueDao"     
   ordered="false" post-set="postSet">
  <structure map-as="com.ited.domain.impl.EntityNameKeyValueDao"/>
  <collection field="toolTips" usage="optional"
create-type="java.util.HashSet" />
</mapping>
----

And the exception when marshaling the above xml:
---
java.lang.ClassCastException: com.bv.core.domain.impl.ContentItemDefault
cannot be cast to com.bv.core.domain.ContentItemGroup
        at
com.bv.core.domain.impl.JiBX_jibx_binding_declare_overviewMungeAdapter.JiBX_
jibx_binding_declare_overview_unmarshal_1_1()
----

The first <group> doesn't contain a nested <group> element, so it should
simple ignore the <collection group> binding as it's "optional".
However, Jibx picks up <item>, marshal it to a ContentItemDefault class and
then add it to the first encountered collection of the group binding, namely
the childGroups collection. It should however ignore this and use the
contentItems collection.


If put the "contentItems collection mapping before the "childGroup"
collection mapping I get the following ClassCastException, probably because
it fails in the second nested group xml snippet:
---
java.lang.ClassCastException:
com.bv.core.domain.impl.ContentItemGroupDefault cannot be cast to
com.bv.core.domain.ContentItem
----

How do I solve this? How do I tell JibX to insert in the correct collection?
- Ed


------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users


-------------------------------------------------------

Fachinformationszentrum Karlsruhe, Gesellschaft für wissenschaftlich-technische 
Information mbH. 
Sitz der Gesellschaft: Eggenstein-Leopoldshafen, Amtsgericht Mannheim HRB 
101892. 
Geschäftsführerin: Sabine Brünger-Weilandt. 
Vorsitzender des Aufsichtsrats: MinDirig Dr. Thomas Greiner.



------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to