S
Scott Harper
Ok, thanks for all the feedback... I knew *not* calling
SessionFactory.close() was probably not very clean. However, I'm not
sure all the suggestions really apply to this particular situation --
let me explain.
This is a web app that has a collection of servlets. Before I had
multiple servlets, I was building the SessionFactory in the init()
method, and closing it in destroy(). With multiple servlets, however,
things change.
There is no main() function (that I have control over)... and I can't
close the SessionFactory when any particular servlet terminates, as
others may still be active.
I don't like the complicated static initialization either. In this case
though, the exceptions are caught and manifest themselves as
ExceptionInInitErrors (or whatever that one is called), so it is pretty
obvious when the servlets don't start. Most (all?) of the exceptions
I'm catching are runtime exceptions anyway. I think the only one I can
really get is the HibernateException.
I originally went with the singleton approach. That might still be the
best way... but even then, how do I know when the object is going away,
so I can close the SessionFactory? I read a little about the finalize()
method, but it doesn't seem that it is really applicable to that type of
cleanup.
I suppose I could just instantiate a separate SessionFactory in each
servlet. Just seems like overkill.
Any other ideas?
thanks
scott
SessionFactory.close() was probably not very clean. However, I'm not
sure all the suggestions really apply to this particular situation --
let me explain.
This is a web app that has a collection of servlets. Before I had
multiple servlets, I was building the SessionFactory in the init()
method, and closing it in destroy(). With multiple servlets, however,
things change.
There is no main() function (that I have control over)... and I can't
close the SessionFactory when any particular servlet terminates, as
others may still be active.
I don't like the complicated static initialization either. In this case
though, the exceptions are caught and manifest themselves as
ExceptionInInitErrors (or whatever that one is called), so it is pretty
obvious when the servlets don't start. Most (all?) of the exceptions
I'm catching are runtime exceptions anyway. I think the only one I can
really get is the HibernateException.
I originally went with the singleton approach. That might still be the
best way... but even then, how do I know when the object is going away,
so I can close the SessionFactory? I read a little about the finalize()
method, but it doesn't seem that it is really applicable to that type of
cleanup.
I suppose I could just instantiate a separate SessionFactory in each
servlet. Just seems like overkill.
Any other ideas?
thanks
scott