aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Stateful and Stateless Session Bean reversed in JBoss? 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 "Stateful and Stateless Session Bean reversed in JBoss?" Watch "Stateful and Stateless Session Bean reversed in JBoss?" New topic
Author

Stateful and Stateless Session Bean reversed in JBoss?

frankie huang
Greenhorn

Joined: Dec 17, 2002
Posts: 18
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".
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
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 ]

<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
frankie huang
Greenhorn

Joined: Dec 17, 2002
Posts: 18
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
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
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

Joined: Dec 17, 2002
Posts: 18
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
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
That is correct.
Let me know if it works OK for you.
Cheers
Sam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateful and Stateless Session Bean reversed in JBoss?
 
Similar Threads
unable to deploy stateless session bean using weblogic 7
the Stateful and Stateless Bean in JBoss is reversed?
NameNotFoundException - but the jndi bound
NameNotFoundException in EJB? could anyone tell me?
Ejb