le_sharingan wrote:
Then, every DAO method that needs to perform a database operation opens a Session from that SessionFactory and closes it when finished.
If you do this, you will get OSUser hibernate provider, which
scales ( or at least used to scale ) really poor...
"open session in view" gives you more performance
- in web application you can outsource session management into
request filter.
And another problem with is is lazy loading of collections....
However, if your session lives longer ( and used by several DAOs )
you will have to ensure that stale session ( every session where error happened ) is discarded safely.
Anyway it's kind of tricky...
At the moment I prefer "lifecycle" session from nanocontainer
( well, I use nanocontainer in my app ) , and struggle to make
hibernate session/transaction constructor-injectable.