I am developing a simple webapp that provides a domain model as RESTful resources. I plan to use JPA2 (Hibernate) with support for SpringMVC REST.
When sorting Hibernate objects in XML / JSON, if the object is detached, it will throw a LazyLoadingException for lazy child associations. If the object is still connected to the Hibernate session, it will almost load the entire database.
I tried using Dozer CustomFieldMapper to determine if a property is a lazy Hibernate Collection that is not loaded, and then returns NULL.
But if we have bi-directional associations, Hibernate eagerly loads the Many-to-strong> One side, and Dozer tries to copy properties that will ultimately be caused by a StackOverflow error in the final loop.
The only work I know to solve this problem is to use DTO and copy the necessary properties only into pure POJOs (DTOs) and then convert to XML / JSON. But for a complex domain model, it is very difficult to copy properties manually.
Is there any other clean / simpler way to (un) sort Hibernate objects?
source share