aspose file tools*
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
Author

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:

@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

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: http://aspose.com/file-tools
 
subject: Problem with Stateful Session Bean