max wrote:
Quote:
* Keep the session open all the time - the docs repeatedly stress not to do this.
AFAIK we just stress to only need if required - and in a swing app this might be required.
/max
Max & Anthony, thanks very much for your quick replies!
Max: I've been leaning in the direction you recommend, of having a long-running session which stays open. However, what happens if there is a HibernateException, for example, we briefly lose a network connection to the DB server? I know I need to close the session in response to the error, would it be valid to open a new session and iterate through every data object I've retrieved, calling reattach with each one so that lazy loads will continue to work?
Anthony: Thanks for your suggestion, I can see how eager loading could be a viable option for some browser-like interfaces. However, my app is not structured with different views, where the user is explicitly switching views and I know when to trigger a re-fetch: instead, I have a single complex view with many trees, lists, and tables that all interconnect through the shared data objects. One JTree in particular in my app is always present on the UI, and it can drill through
almost every data object in my relationship graph without ever switching to a different view. Lazy loading would be ideal in this scenario, since I didn't write the TreeModel and thus cannot insert code to trigger Hibernate when a node is expanded (and I wouldn't want to add that to my TreeModel even if I did own the code). Also they might have many different nodes visible, or perhaps only one, so it would not make sense (and the app would run out of memory) if I tried to eagerly retrieve all nested info for every object in the JTree.