Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sessions in Hibernate

 
glenn spjuver
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a webapp that will only (almost) be reading from- and never updating or inserting stuff into the database. Is there some intelligent way to use Hibernate Sessions in order to fully take advantage of the "cache" they provide.
One thought I had was to use "long sessions" to let the Hibernate Sessions live throughout the user session. Is this possible? And how then do I know when to close the session?
Also, would it be possible to let several users use the same hibernate session, I mean if concurrancy is not an issue? Perhaps that's a really dumb question, but please bear with me -I'm just a greenhorn .

Regards
 
hernan silberman
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're best off depending on the Level 2 cache, instead of reusing the Session cache. I would recommend this very common approach:

1) Use a connection pool. This way you don't end up doing the heavy lifting to rebuild a new connection for each request you get.

2) Select and use the Level 2 cache. Read up on the details of how to do this properly, the Hibernate documentation is really strong on this topic.

3) Once you have read the documentation, you will understand how to properly query your Hibernate entities so that Hibernate checks the Level 2 cache before assembling your objects from scratch from the database.

hope this helps...
Hernan
 
glenn spjuver
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I've done some reading on the second level cache, and it seems they best way to go.
 
Sebastian Hennebrueder
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To precise you should use the query cache and read-only mappings.
This will get you the best performance.
Keep the session short.
I made some time studies for my book and it is really a large difference.
Regards Sebastian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic