When mapping to an instance instead of a Class it happens that the existing instances are replaced by new ones.
The following test shows this behavior and will fail with an AssertionFailedError:
public void test() {
// create one instance of each DT and setup the relations
DtA a = new DtA();
DtB b = new DtB();
DtC c = new DtC();
b.setC(c);
a.getBs().add(b);
// map to Entities
EntA entA = mapper.map(a, EntA.class);
// map back from Entity to given Datatype instance
mapper.map(entA, a);
assertTrue("The DtC instance differs", c == a.getBs().get(0).getC());
}
The test-code and a patch based on tags/5.3.2_RELEASE is attached.
the test-code
The patch based on Dozer 5.3.2