permaculture playing cards
The moose likes EJB and other Java EE Technologies and the fly likes Problem with Stateful Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem with Stateful Session Bean" Watch "Problem with Stateful Session Bean" New topic

Problem with Stateful Session Bean

Marcin Kwiatkowski
Ranch Hand

Joined: Aug 06, 2007
Posts: 32

Hi! I'm using JSF + EJB3 and Jboss4 as server.

Session bean looks like this:

public class UserManager implements UserManagerLocal{

private User user;
private Date date;
private String text;

public void test(){

public void addDate(Date date){ = date;

public void addText(String text){
this.text = text;

public void start(User user){
this.user = user;

public void finalize(){

public class ManagedBean {

private String text;

private UserManagerLocal getUserManager{
InitialContext ctx = new InitialContext();
return (UserManagerLocal) ctx.lookup("Orchid/UserManager/local");
}catch(Exception e){
throw new RuntimeException("couldn't lookup UserManager", e);

public String addText(){

public String addDate(){
getUserManager().addDate(new Date());

public String start(){


The problem is everytime I'm calling one of these(addDate, addText, ...) methods looks like I'm getting new instance of stateful bean.
[ December 28, 2008: Message edited by: Marcin Kwiatkowski ]
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
Each time you look the EJB from JNDI a new instance is created, you should store it somewhere (like in HttpSession).
[ December 28, 2008: Message edited by: Raf Szczypiorski ]
I agree. Here's the link:
subject: Problem with Stateful Session Bean
It's not a secret anymore!