Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

HCP CDI and statefullness of @stateless beans

Hi all,

i probably miss something, but i am curios anyhow.

I have a webfilter which uses CDI to inject some beans. All of those beans are stateless. To my understanding that would mean they are request scoped but they seems to be session scoped.

According to "the internet" it depends on the container. Could maybe someone shed some light on how stateless beans are handled in HCP? and is there a way to make them request scoped? I tried but did only produce dumps

regards

Mathias

replied

Hi Mathias!

I think you are misunderstanding what @Stateless means. From the EJB spec we can read:

"Stateless session beans are session beans whose instances have no conversational state..... Because all instances of a stateless session bean are equivalent, the container can choose to delegate a client-invoked method to any available instance. This means, for example, that the container may delegate the requests from the same client within the same transaction to different instances, and that the container may interleave requests from multiple transactions to the same instance. "


This means that the EJB container is NOT required to create a new instance on each request. Also it means that you must NOT store any state-full data in the instance variables, because it is not guaranteed that the next business method call will be executed on the same instance. You can use a @PostConstruct method to reset all residual state of teh bean, but still - DO NOT USE instance fields to store STATE in a stateless bean.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question