Orika and Hibernate Managed Collections

421 views Asked by At

I'm currently using Orika to map between Hibernate managed domain objects and Models (DTOs). I do this because I want to merge the collections when going from Model --> Domain so that if no changes are made, the Hibernate version number of the entity does not iterate. I initially set up a mapper defined with the following:

A extends CustomMapper<List<Domain>, List<Model>> { ... }

This works fine in a unit test that doesn't actually use the persistence layer, but when I do an integration test with Hibernate this doesn't get invoked at all. In fact, the collections in my objects never get populated in either direction. Digging uncovered that this was due to Hibernate using PersistentList (implements List, but with no type information). So now I have two mappers:

A extends CustomMapper<List<Domain>, List<Model>> { ... }
B extends CustomMapper<PersistentList, List<Model>> { ... }

If I remove A, then Orika acts like the mapper doesn't exist at all. I think this is because when it's analyzing all the class maps i provide it doesn't find anything that matches PersistentList and so it isn't included.

If I remove B, then Orika will not properly map Hibernate returned domain objects to models, because it will not map PersistentList.

Is there a way to make this cleaner? How can I define a single mapping that covers all cases in a non-ambiguous way?

0

There are 0 answers