What is the difference between injecting a stateful ejb bean inside request scoped session bean vs injecting a stateless ejbbean inside request scoped session bean? Does request scoped bean creates a new instance for stateful bean each time it is called?
Asked
Active
Viewed 978 times
4
-
I understand what you said. I'm more concerned about how to store session in an EJB applicaton using stateful bean .Can u elaborate on it? How to call stateful session bean to perform business logic from jsf maanged bean? – Prateek Sharma Dec 26 '14 at 03:19
-
Thanks for your reply.. Actually, I can store session using JSF/CDI session scoped beans and use stateless beans for most of the business logic but then it really makes me think what is the use of stateful bean then. I thought that stateful beans are used for storing session and it is the replacement of HTTP session object. – Prateek Sharma Dec 26 '14 at 03:51
1 Answers
2
- Before a stateful session bean is deployed, it is in the Does Not Exist state. Upon successful deployment, the EJB container does any required dependency injection on the bean and it goes into the Ready state. At this point, the bean is ready to have its methods called by a client application.
- When a stateful session bean is in the Ready state, the EJB container may decide to passivate it, that is, to move it from the main memory to the secondary storage. When this happens, the bean goes into the Passive state.
- If an instance of a stateful session bean hasn't been accessed for a period of time, the EJB container will set the bean to the Does Not Exist state.
- A stateless session bean life cycle contains only the Does Not Exist and Ready states, stateless session beans are never passivated.
- RequestScoped Bean lives as long as the HTTP request-response lives.
so your stateless bean inside a request scoped backing bean will destroyed after HTTP request-response but the stateful one will go to the passive state.

void
- 7,760
- 3
- 25
- 43
-
Thanks for your answer. Can u elaborate on how to store session using stateful bean by calling/injecting it from jsf managed bean? – Prateek Sharma Dec 26 '14 at 03:23
-
I can store state in JSF session scoped beans and use stateless bean for business logic but i want to try to use stateful bean for storing session as stateful bean is the replacement of HTTP session object. – Prateek Sharma Dec 26 '14 at 03:56
-
You're welcome, I don't know exactly what do you want to do and why you are using a stateful bean inside a request scoped backing bean but you can use **FacesContext.getExternalContext().getSession/getSessionMap() ** to retrive or store session's object. good luck. – void Dec 26 '14 at 04:20