otis wrote:
Making a new Hibernate Session is inexpensive. However, once I start data that I already accessed, I would have to re-fetch it from DB if I were to use a new Session every time. That, I though, was the first level of cache - Hibernate Session 'remembering' data about previously loaded entities.
No?
Yeah, I do use session.reconnect() and session.disconnect().
Thanks!
"session.reconnect() " is an anitipattern for many reasons.
It is possible to make this way thread safe with some fake attribute in httpsession and Filter, but I see no way to manage resources, your user becomes resource manager on server.
The most simple scalable way is to create session per request, but you will lose
performance. Workaround for performance is cache, a global object cache (independant on user count), content cache, query cache ("materialized view"),
indexes and configuration parameters.
There are more ways to increase performance than scalability and it is better to think about scalability first, it depends on application architecture.