Currently doing a test-app with JCR (Modeshape).
The abstracted flow is as follows: session.open, a repository fetches on or more nodes related to a query, session.close.
The resulting nodes contain properties, etc. that I need to present to the view. I currently have the naive setup of letting the view take properties from the jcrNode directly. However this gives an error like: "The session with an ID of 'e2881d98-56fd-4a57-9cce-1a7d087a11e8' has been closed", which makes sense.
I believe the general approach (please correct if otherwise) would be to create some sort of nodeDTO which is populated by the jcrNode when the session is still active. The view is then free to use the nodeDTO however it wants.
Now, the perfect structure for such a nodeDTO would mimic the structure of the jcrNode 1-to-1 so why not use the jcrNode as the DTO itself? This would be accomplished with something akin to hibernate detach/attach. I realize that a jcrNode (with its children) can contain lots of data, so there should likely be some parameters to determine the depth of detachment, etc.
Another approach would be to have something like the openSessionInView-pattern, although this would be mvc-framework specific.
So I can see several approaches to this, best approach first (imo):
- detach/attach functionality for jcrNodes
- good library of helper classes to create the DTOs
- openSessionInView
Any comments on to the 'best-practice' approach, etc. much appreciated.