Hi Niemann,

You need to do something about the circular references for this to work properly. The easiest approach is to make the id property of DealHead an identifier, with ident="def", then make the dealHead field of DealDetail a reference, with ident="ref". That should give you what you want.

Note that it's more common for XML to use nesting to indicate ownership, so that typically the XML representation of the DealDetails would not actually have a link back to the parent DealHead. To make that work properly you'd need a way of setting the references when unmarshalling. One easy way is to define an addDetail() method to the DealHead class. This method would set the DealDetail dealHead field to "this", then add the DealDetail to the HashSet.

 - Dennis

Niemann Alexander wrote:

Hello everybody,

I encountered an error marshalling the following class:

public class DealHead {
    private Long id;
    private Set dealDetails = new HashSet();
    ....
}

The collection dealDetails contains instances of DealDetail, whereas a DealDetail contains a reference back to it's parent:

public class DealDetail {
    private Long id;
    private DealHead dealHead;
    ...
}

My binding file looks like this:

  <mapping class="de.ava.kas.model.DealHead" name="deal-head">
    <value name="id" field="id" usage="optional"/>
<collection field="dealDetails" usage="optional" item-type="de.ava.kas.model.DealDetail" type="java.util.HashSet"/>
     .....
  </mapping>
  <mapping class="de.ava.kas.model.DealDetail" name="deal-detail">
    <value name="id" field="id" usage="optional"/>
    <structure field="dealHead" usage="optional"></structure>
    .....
  </mapping>

Now, when I try to create the XML from my DealHead objects I get an error: java.lang.OutOfMemoryError: Java heap space

I guess that JiBX gets into an endless loop trying to solve the bi-directional relationship between DealHead and DealDetail (head contains detail containg head containing detail and so on). As soon as I leave the collection DealHead.dealDetails empty or remove the mapping from my binding it just works just fine.

Are there any suggestions how this problem can be avoided without changing the classes? Did I make any mistakes in my binding?

Thanks in advance,
Alexander



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to