• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Stateful Session Bean

 
Ranch Hand
Posts: 32
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic