• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Stateless session bean confusion

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am very new to ejb and I have a confusion regarding stateless session bean.
I have created a instance variable inside the session bean ;and inside my business method I am appending the method parameter in the variable.ThenI am calling that method twice from client by passing the parameter "First" and" "Second" respectively and printing the value of the variable.
Now here is my confusion.As per my knowledge stateless session bean does not hold the state between successive method call.So i expected the output "First" and "Second" as during the 2nd call the variable should not contain any value during the first call.
But I am getting output as "First" and"FirstSecond". My confusion is Why in the second time it is holding the first paramvalue?
Below I pasted my code snippet :-
1) Session Bean Implementation Class

}
2) I am calling from client by :-
ejbRemote.returnString("First");
ejbRemote.returnString("Second");
3) ejb-jar.xml is as follwes
<ejb-jar id="ejb-jar_ID">
<display-name>EJBProject</display-name>
<enterprise-beans>
<session id="EJBProject">
<ejb-name>EJBProject</ejb-name>
<home>beans.EJBHomeInterface</home>
<remote>beans.EJBRemoteInterface</remote>
<ejb-class>beans.EJBBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

Thanks in advance.

[edited to add code tags]
[ August 27, 2008: Message edited by: Jeanne Boyarsky ]
 
author & internet detective
Posts: 41407
854
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dwijen,
The bean is functioning correctly. In fact it is functioning just like a normal Java object. It's not that the stateless session bean doesn't hold instance variables, it's that it shouldn't hold user state. You also can't rely on getting the same bean each time so the information may or may not be available. However if you are holding something general - like an instance to a DAO factory - all users of the bean would want it.
 
Dwijen Bhattacharjee
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeanne. Thanks a lot. but i didn't understand the last line "However if you are holding something general - like an instance to a DAO factory - all users of the bean would want it". I am new to EJB world .So I don't have detail knowledge. It will be great if you explain these more.
 
Jeanne Boyarsky
author & internet detective
Posts: 41407
854
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dwijen Bhattacharjee:
Thanks Jeanne. Thanks a lot. but i didn't understand the last line "However if you are holding something general - like an instance to a DAO factory - all users of the bean would want it". I am new to EJB world .So I don't have detail knowledge. It will be great if you explain these more.


Sure. I'll explain via two examples:

Bad practice. Don't do this:


Ok practice:


"Factory" and "DAO" are both patterns. A factory creates other objects - in this case the DAO objects. A DAO (data access object) accesses the datasource. For example, it might contain the actual JDBC code.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic