EJB programming & troubleshooting: where can I store information in stateless EJB ?
I need to store information (Map) in Stateless EJB. I need this information to be kept during the session of the EJB (from the point the EJB invoked until it ends). if I were used servlets I could use the ServletContext for that, but I work with EJB. Is there any "best practice" for that ?
- Posted by: Yonatan Maman
- Posted on: October 21 2006 14:41 EDT
- Re: where can I store information in stateless EJB ? by Nicke G on October 25 2006 08:23 EDT
- Re: where can I store information in stateless EJB ? by Amit Kasher on December 02 2006 08:09 EST
How about using a stateful session bean, given that the map needs to be unique for each session?
You should clarify your question... If you refer to information that should be kept in between calls from the same client (the same EJB proxy object), use stateful EJB. I'd suggest reading this: http://www.onjava.com/pub/a/onjava/2001/10/02/ejb.html If you want to have a data object accessible from an EJB, create a classic singleton object and use it from your stateless EJB. This requirement usually arises when you need to hold a cache somewhere. Let other mechanisms (tip: inside your persistence provider) do the caching for you. Aside from the fact that cache is overused IMHO, it is implemented in so many infrastructures that usually you don't need to implement it yourself.