Can I use EJB Stateless Bean with CDI to maintain user session?
cdi, ejb-3.1, java, java-ee-6, jsf-2
Solution
Stateless beans cannot maintain shopping carts or session; that's what "stateless" means.
You need either a stateful EJB or to do it in the web tier. Those are the only places where session is maintained.
Problem
Based on this post http://www.adam-bien.com/roller/abien/entry/ejb_3_1_killed_the I use in my app @Named @Stateless bean for communication with a database (injecting EntityManager here) and display information on a jsf page. It's great facilitation since Java EE 5, but I have one question. Is it secure to use such beans for maintaining a user session (shopping cart etc)? I read a book about ejb 3.0 and I know that the same stateless bean could be used with many clients. What's the best approach to use a managed bean with all ejb features (transactions, thread safety etc)? I mean any other way than managed bean + ejb interface with implementation + ejb injection as in Java EE 5? I use GlassFish 3.1 WebProfile