Is this a bug? stateful session bean is acting like stateles
siupetpet Jul 19, 2004 10:16 PMHello, please read my post and give me some insight on this "strange" behavior. I am in the learning stage of understanding the difference between stateful and stateless session beans. Here is what I did:
I've created a stateLESS, container managed session bean; in the bean class there is a private int testInt variable, and there's a public void increment() method that increases testInt by 1 and then prints its value using System.out.println(testInt). This method is properly declared in the remote interface. In the ejbCreate, ejbRemove, setSessionContext, etc methods, there's System.out.println("ejbCreate"), System.out.println("ejbRemove"), System.out.println("setSessionContext") statements for tracing/debugging purpose.
My ejb-jar.xml file looks like
<ejb-jar>
<enterprise-beans>
<ejb-name>TestBean</ejb-name>
TestHome
Test
<ejb-class>TestBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
Transaction attributes for 'TestBean' methods
<ejb-name>TestBean</ejb-name>
<method-name>*</method-name>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
Then the client does the usual lookup("TestBean") without a hitch, and calls the increment() method several times. The interesting thing is, on the JBoss console, I see
[stdout] setSessionContext
[stdout] ejbCreate
[stdout] 1
[stdout] 2
[stdout] 3
[stdout] 4
...
ON THE OTHER HAND, if I change the <session-type> attribute from stateLESS to stateFUL, and keep the rest the same, I see the following on the JBoss console when I make several calls to the increment() method:
[stdout] setSessionContext
[stdout] ejbCreate
[stdout] 1
[stdout] setSessionContext
[stdout] ejbCreate
[stdout] 1
[stdout] setSessionContext
[stdout] ejbCreate
[stdout] 1
...
Don't stateful and stateless session beans have their meanings inverted???
Please please help me understand this. Thank you so much :)
I don't know if I should post all the codes, since it will take up extra space on the forum.