Hi all,
I am a new hibernate user and I am currently building a web application with Hibernate 2.1.2, Spring and Tapestry.
I am wondering how (and where) I should retain business objects (beans) between each http request/response.
I read carefully hibernate docs and looked for answers to this in this forum but did not find any.
Basically, my application is some sort of eCommerce application where users may log in, put assets in a basket, etc...
- Therefore, there are some informations I need to keep between each http cycle (user logged in, basket, etc...).
- And I do not want to hit the database at each http cycle to get these informations.
I can think of different strategies :
1/ Keep the beans in my http session (actually, in Tapestry, this is a visit object but this is not important here). I don't like this because I'd like to keep my http session as light as possible and serializable for potential load balancing requirements
2/ Only keep bean's IDs in the http session and retain myself in some sort of singleton in the business layer the corresponding beans in maps where keys are the IDs. At each http request, I'd get the ID from the http session and then the beans from the maps.
This solution is actually making me maintain a cache but why not ?
3/ Only keep bean's IDs in the http session and rely on 2nd level JVM cache (ehcache for instance) to keep beans. Then, I would get them back at each cycle using load method.
I am sure I am not the first one to have to make such a decision. What are the advantages/drawbacks of each strategy considering the way Hibernate works ?
And yes, I have read the doc about Optimistic Locking/Versioning but this does not lead me to a clear answer.
Thanks a lot for your answers, remarks, references.
Regards
_________________ Thomas Salomon
eComposite
www.ecomposite.fr
|