I am developing a Spring MVC facade to access to a number of services. There are no DTOs implemented, and due to the magnitude, it is currently not an option to do so.
Serialization is done by Jackson directly to entities returned to the controllers as a result of transactional invocations to methods in the services, which fetch the entities from DB through the ORM (Hibernate).
The problem comes with entities that have collection attributes (such as Sets) from one-to-many or many-to-many relations, that Hibernate returns as PersistentCollections (like PersistentSet), and are lazy loaded, due to which, can't be read outside the scope of the DB session (which is when Jackson is attempting to serialize the response from the Controller).
Ideally, I would like Hibernate to return Java collections of proxies (HibernateProxy) that do maintain a reference (identifier) to the entity they wrap. Could also work to keep using specialized data structures (like PersistentCollection) but keeping references to the items wrapped, since once wrapped, they can only be retrieved from within a map that lives in the BD session, and without it, the key to the collection is completely useless (why do it like that? what if we don't want the whole item, and just it's identifier to be serialized as a reference? sigh).
I wonder...
Is it possible to force Hibernate to return Java collections of proxies wrapping entities?
If not, is it possible to extend Hibernate collections (like PersistentCollection) to maintain references to the entities wrapped, in order to read them in a specialized Jackson-Hibernate serializer?
If not, is it possible to convert Hibernate collections to Java collections before closing the BD session, without using additional data structures, besides the entity itself (i.e. convert the collection back to a Java type)?