RayDeCampo wrote:
In this case my business logic dictates that the record would not be deleted.
Ah, but the general advice was written as general advice, not as an instruction on how to implement your particular business case.
RayDeCampo wrote:
I'm having trouble understanding this one. Why does the refresh() throw an exception? What is the difference if there has already been a cycle of exception-new session?
Because the object you're refreshing was loading in session A. A reference to this handle is recorded in the object. Since there was an exception in session A, and since you're following the hibernate rule that you must discard and recreate a session if an HibernateException is thrown, you are now in session B. sessionB.refresh(objectFromSessionA) will not work. In fact, it'll throw another HibernateException, causing you to throw away sessionB and create sessionC.
RayDeCampo wrote:
How does calling refresh() "hang onto system resources"?
It doesn't. A long session does. It refers to a cache (or two), a JDBC connection, a SessionFactory, and so forth.
Quote:
It's a web session "variable", not global.
These is a possibility of miscommunication here. Do you mean that it lasts the duration of a single web request? If so, that's a short session, not a long session. refresh() to your heart's content. If you mean that it lasts the duration of one user's log-in (potentially several hours or longer), then that's a long session, and so the session is a global variable. Global != infinite, it just means that any "normal" code can expect to have it available, it's not scope-limited to a particular class or method.
Hope that this is making things clearer for you.