When calling a remote service (e.g. over RMI) to load a list of entities from a database using Hibernate, how do you manage it to initialize all the fields and references the client needs?
Example: The client calls a remote method to load all customers. With each customer the client wants the reference to the customer's list of bought articles to be initialized.
I can imagine the following solutions:
Write a remote method for each special query, which initializes the required fields (e.g. Hibernate.initialize()) and returns the domain objects to the client.
Like 1. but create DTOs
Split the query up into multiple queries, e.g. one for the customers, a second for the customers' articles, and let the client manage the results
The remote method takes a DetachedCriteria, which is created by the client and executed by the server
Develop a custom "Preload-Pattern", i.e. a way for the client to specify explicitly which properties to preload.