Question

I'm converting some code to take advantage of EJB 3 and I've come up with a scenario where I have a @Stateless EJB being injected into JSF Managed bean that is annotated with @SessionScoped.

I was wondering how this effected the life of the EJB? Does it remain stateless and get destroyed after each call to one of its methods or does the same bean exist for the duration of the session?

Was it helpful?

Solution

As stateless EJB session beans are pooled by the server, there is no direct relationship with their lifecycle and the lifecycle of other session scoped beans. The webserver creates and destroys such beans when it needs to.
From the EJB spec:

The container can perform the instance creation at any time—there is no direct relationship to a client’s invocation of a business method or the create method.

For more information see the specification (around page 99).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top