Menu

StackOverflowError when mapping object graph

Help
2011-10-14
2014-03-05
  • Fabien Coppens

    Fabien Coppens - 2011-10-14

    Hi all.
    Here is my use case: I am unmarshalling from XML, using JAXB, to a graph of objects in package com.foo.binding, which are copies of my JPA entities from the ORM layer, the latter being in package com.foo.persistence. Thus, the idea is to unmarshal the XML and copy the new graph to the same JPA-annotated object graph and persist those objects.
    So here is what I am trying to do:

    Mapper mapper = new DozerBeanMapper();
    com.foo.persistence.A mappedA = mapper.map(a, com.foo.persistence.A.class);
    

    where a is an instance of com.foo.binding.A, and has exactly the same properties as com.foo.persistence.A.
    So I am expecting the mapping to be completely implicit and straightforward.
    The particularity of the object graph is that it contains bi-directional relationships. I.e., we have

    public class A {
    private Set<B> setOfB;
    private Set<C> setOfC;
    private Set<D> setOfD;
    }
    

    and each of B, C, and D has a property of type A, e.g. :

    public class B {
    private A a;
    }
    

    When I attempt to perform the mapping, Dozer goes into an infinite loop and I get java.lang.StackOverflowError.
    I'm using Dozer 5.3.2.

    Help ?

     
  • Mourad ZAMOUN

    Mourad ZAMOUN - 2014-03-05

    I have the same error !
    if you have the answer, I'm interested
    Thanks

     

Log in to post a comment.