• 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

Stateful and Stateless Session Bean reversed in JBoss?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I deploy a stateful session bean, the state can't keep; while a deploy a stateless session bean,the state keep. why?
my session bean:

the ejb-jar.xml

the client code:

when I code "stateful" in the ejb-jar.xml, I found the result is always "1" even I refresh the browser times. when I code "stateless" in the ejb-jar.xml, I found the result is "1",and then "2" and then "3"...
I feel puzzling, it does not obey the book "Mastering EJB".
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The stateless bean behavior is absolutely correct. A stateless beans member variables are always maintained (per bean instance) across calls by ALL clients. This means any client that calls your bean will increment the variable.
The fact that you are creating and then 'removing' your bean means that the stateful bean is lost with each call. If you take out the code that removes the bean, you will probably find that this works fine.
Sam
[ January 13, 2003: Message edited by: Sam Dalton ]
 
frankie huang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Though I remove the "remove" code,the result is not changed and the member's state can't keep. And I found the bean call "setSessionContext()" & "ejbCreate()" & "count()" every time I call it in the client. the STDOUT:
 
Sam Dalton
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you call create() you are creating a NEW instance of your stateful bean (with default values for the fields) you need to, instead, store the reference to your Stateful bean and reuse that (the HttpSession is a good place to store such a reference)
Cheers
Sam
 
frankie huang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sam Dalton:
when you call create() you are creating a NEW instance of your stateful bean (with default values for the fields) you need to, instead, store the reference to your Stateful bean and reuse that (the HttpSession is a good place to store such a reference)
Cheers
Sam


oh,I must keep it in Session manually? I see,Thank you!
 
Sam Dalton
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is correct.
Let me know if it works OK for you.
Cheers
Sam
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic