• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I do that

 
pardha saradhi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a stateless session bean. I am adding books from client and getting them.
when I run the client program again books are adding cumilatively. and other client is getting the first clients plus the current cliets data.
How can I handle that
Thanking you in advance
Saradhi
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you tell us more about your program (like how you store the books) we have absolutely no way of helping you. You really must give us enough information to go on!
Offhand, it sounds like you might be storing your books in an instance variable of the session bean. This is an extremely bad idea -- after all stateless means "no state" e.g., no instance variables.
Normally, the stateless session programming model would involve taking information from a client request, putting in into a data store (like a JDBC database) and then exiting. Is this what you are doing? Why not post some code to show us?
Kyle
[ February 04, 2002: Message edited by: Kyle Brown ]
[ February 04, 2002: Message edited by: Kyle Brown ]
 
pardha saradhi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi please I am pasting my code
I am using vector to store information.
public class BookBean implements SessionBean
{
SessionContext ctx;
Vector v = new Vector();
All interface methods
------------
----------
--------
public void addBook(String str)throws RemoteException
{
v.add(str);
}
}
my Client prog.

remote.addBook("VB");
remote.addBook("ASP");
remote.addBook("EJB");
remote.addBook("Java");
remote.addBook("Oracle");
bookList = remote.getContents();
Enumeration e = bookList.elements();
while(e.hasMoreElements())
{
System.out.println(e.nextElement());
}
when ever I run this code it adds books and displays. Again when I run the same code current list and the previous list are printing
how to handle that. Container will take care of that or I have to handle in code?
Hope u got my problem.
Thanking you
Saradhi
 
Steve Chernyak
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Kyle said you are storing the books into an instance variable:
Vector v = new Vector();
This will only execute once when the bean is created. Since the container will reuse this session bean the second time you execute this code it might or might not use this instance, if it does the books will be added to the vector and both the old ones and the new ones will print.
Depending on what you are trying to do you should either store the books into a persistent store like Kyle said, or use a statefull bean.
SteveC
 
pardha saradhi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you now I am clear. Now one more thing
If I convert this into statefull bean through J2EE DepoyTool without making any changes to the code will it work?
Thanking you
Saradhi
 
Steve Chernyak
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it
I don't think it will be a problem.
SteveC
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!