Hi I am working on hibernate and need some information about the stateless session. tried to search on google but didnt get that much information. so please need any link or pdf's about stateless session on how, why and when to use it. what are the pros and cons of using it. thanks
A stateless session does not implement a first-level cache nor interact with any second-level cache, nor does it implement transactional write-behind or automatic dirty checking, nor do operations cascade to associated instances. Collections are ignored by a stateless session.
A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean's instance variables may contain a state specific to that client but only for the duration of the invocation.
There isn't much to say about Stateless Sessions, anyway. Basically, it serves only one purpose: to not cache anything at all.
In regular sessions, Hibernate maintains a "session-level cache", which is cleared when you close your session, for instance. In some other cases, you can plug a caching mechanism to act as a "second level cache", which is complimentary to this "session-level cache" and can survive even after a session is closed.
However, this can be a problem if you are in a batch-operation mode. For instance, it doesn't makes sense to keep any entity in the cache (session-level) if you are just reading an input file and inserting entities in the database. You know you won't need that entity anymore. So, that's where you use the Stateless session.
There's no change in the API, just changes in the implementation.
Take a look at this link. This is all you need to know about Stateless Sessions: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/batch.html#batch-statelesssession
The book Java Persistence with Hibernate has a short, but sufficient section about stateless session in Hibernate. If you do not want to buy a copy of that book just for that information, I found the whole book on slideshare.com; Section 12.2.3, page 539 (page 574 on slideshare.com).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With