Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Stateful Session Bean

 
Marcin Kwiatkowski
Ranch Hand
Posts: 32
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I'm using JSF + EJB3 and Jboss4 as server.

Session bean looks like this:

@Stateful
public class UserManager implements UserManagerLocal{

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

@PostConstruct
@PostActivate
public void test(){
System.out.println("test");
}

public void addDate(Date date){
this.date = date;
}

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

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

@Remove
public void finalize(){
....
}
}

public class ManagedBean {

private String text;

private UserManagerLocal getUserManager{
try{
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(){
getUserManager().addText(text);
}

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

public String start(){
getUserManager().start(user);
}

}

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
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic