christian wrote:
Remember that your primary option is to fetch all required data (the subgraph you need) before you pass back to the client tier! Hibernate has very flexible fetching, with HQL and Criteria. Lazy loading is the second option and I'm not convinced that it makes sense across tiers. We've been thinking about that several times, and any "automatic" lazy loading with a new Session would break transactions (Detached Objects pattern requires version checking).
Your approach, with a single Long Session (disconnect/reconnect pattern) per application transaction, may be valid, but I really fear that users don't understand it and use it instead of fetching. Why not implement a patch and discuss the implications of that on the developer list?
The advantage I had seen with lazy loading across the tiers was that a GUI could allow users to "turn off" unwanted data for viewing in preferences. The client layer could leverage lazy loading to only retrieve data that was required.
I guess one alternative is to have the client specify what data to fetch. Another is to have the service layer return the maximum sub-graph likely to be needed. I will probably go with one of these latter options.
I had a look at CarrierWave. While I liked the ability to specify a fetch depth and 'fuzzy' ends (ie. ends that are remote references), I didn't like the code-generation approach, and I found the whole architecture overkill for what I was looking to achieve.
On a side note, I think a useful api would be something similar to CarrierWave (or Service Data Objects), with the ability to specify (in configuration or in API), at a fine level which properties should be copied by value, and which should be made remote calls. The proxy object transmitted to the client side would need to record any changes made to the copy-by-value data (ie. by the client), and transmit all these changes prior to any calls to the remote method calls, to synchronise its state with the remote POJO. The advantages would be that rich domain models could be modeled and transmitted to the client without the client needing all the support classes on the classpath, and the network traffic could (hopefully) be reasonably efficient. But then again, this all could be an unnecessarily complicated alternative to a well-designed service layer.
gavin wrote:
Quote:
Why not implement a patch and discuss the implications of that on the developer list?
Absolutely not. I am an immediate veto to anything like this.
Just curious, but what are the objections to this?
Scott