my opinion:
Quote:
1. What is the overhead of opening up the session on every function call, flushing it, and closing?
2. Does it make sense to store sessionFactory elsewhere? Should it be in the context somewhere, accessible to all connections? Any pitfalls with this?
3. If the above solution is not optimal, what would be a better way of doing this?
1- if you are flushMode = auto (by default), you should consider not manullay flush it, if you have a "commit" function, to be 100% secure you can call session.flush() and then commit
2- the best for a webApp is to use threadLocal Pattern (search open session in view on site) it's the simpliest way to manage hibernate session (and maybe sessionFactory) for such apps
3- see previous point.
Creating a sessionFactory = very expensive
Obtaining a session from a sessionFactory = not expensive
Flushing a session = can be very expensive if you call it every millisecond...[/quote]