• Post Reply Bookmark Topic Watch Topic
  • New Topic

using stateful beans (Java EE5) so that new instances become created in the right way

 
Ylva Degerfeldt
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to learn how to use stateful session beans by using them as intermediate "storage objects" when I'm creating an account on my test web page (called "Pet Maniacs").

I have a start page (Index.jsp) with a "Create account-button". When the client clicks on it a new window opens up which shows a form (Personal_info_form.jsp).
When the client has clicked the Submit button I'm sending the information to my servlet (UserAccountCreatorServlet), which has a stateful session bean called UserAccountCreatorBean as an instance variable.

The servlet passes the information on to the stateful bean, which saves it, and then the servlet shows the next form, receives information from it, saves it in the bean again and shows the last form (confirmation_form).

When the client has confirmed that the information is correct the servlet is called again and now it calls the "CreateAccount" method of the stateful bean. This method has the Remove annotation (which I've learned that I should have).

After that the account is created and the bean instance has been removed.
So far so good, but I would like to be able to simulate that several users create accounts after one another (without having to rebuild the application).

I tried to do that by just clicking on the Create account button on my start page again (which is left "untouched" since all the "action" happens in a different window), hoping that I would now count as a new client. (I'm not so good at how this stuff actually works.)

But I always come back to the servlet with the Same Old bean instance as before, and that one is Dead!
How are new bean instances actually created?

I can add that I've injected my bean using @EJB.

Can someone please help me?

I can add some code later if needed. For the moment I'm leaving this message as it is since it's very long already.

/Ylva
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35743
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ylva,
Since you are the same user (same browser session), why would you expect to get a different bean?

If you were to open a different browser (or close the current one and reopen it), you would be treated as a different user.
 
Ylva Degerfeldt
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jeanne, for answering.

The reason I believed that it could become a new session when I click on the "Create account" button a second time was that once I compared the session ids between the first window opened by the first "Create account-call" and the second window (my second account creator try) and they WERE different. But I guess something had gone wrong then 'cause when I recently tried it the ids were the same and I think you're right.

Anyway, I've tried reopening the index page (and creating a new account) in Internet Explorer after first having created one account in Firefox and also tried opening it in a new Firefox window but I still got the same error I always get:

javax.ejb.NoSuchEJBException

I guess this means that the servlet is still stuck with that same old bean instance and that's Not what I want.

I've tried invalidating the current session and I've even tried destroying the servlet, but none of those things worked.

I also read about putting a bean inside the current session and I tried that too but it didn't help.

I'm really lost here. What am I doing wrong?

Perhaps I should show you some of my code:




And some of the bean code:


I can add that I'm using local interfaces for my beans, but that can't be the problem or can it?

I would be deeply grateful if you, Jeanne, or someone else could help me with this problem 'cause it's very annoying that I don't understand this. (In the book "EJB 3 in action" they're using a stateful bean when creating a user account so it's Supposed to work!)

Thanks in advance!

/Ylva
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!