File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Session Bean Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Session Bean Doubt" Watch "Session Bean Doubt" New topic

Session Bean Doubt

Shanmugam Karthikeyan
Ranch Hand

Joined: Aug 02, 2002
Posts: 58
1. Which statements about stateful and stateless session beans are true?
(Choose all that apply.)

a). Only stateful session beans support transactions.
b). Only stateful session beans can be passivated.
c). Only stateful session beans have a 'setSessionContext' method.
d). Both stateful and stateless session beans can support
overloaded 'ejbCreate' methods.
e). Both stateful and stateless session beans can implement
the 'javax.ejb.SessionSynchronization' interface.
f). Both stateful and stateless session beans can have instance variable state.

ans given : b,f - how a stateless session bean can have state in an instance variable.
my answer : b

SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3
Ugender Rekulampally
Ranch Hand

Joined: Nov 14, 2005
Posts: 135
answers B and F are correct. session conversational state is different from instance variables state. but in stateless session bean, if you declare any instance variables, becareful in handling them. or you will see unwanted results.

wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Also see this thread
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
I am not clear about option b.
stateless session beans can also be passivated but their passivation is not required and in their normal lifecycle their passivation is not required.
**and one more,in all types of beans we have to define ejbPassivate()
Patrick Williams
Ranch Hand

Joined: Apr 03, 2005
Posts: 213
Hi Raj, I'm not sure I agree with you. Although those beans inherit those methods from javax.ejb.SessionBean, they are never called in a stateless session bean. Stateless beans are "awake" as they sit in the instance pool so there is no need to wake them up (ejbActivate())or put them to sleep (ejbPassivate()). Also, they do not keep conversational state so there is no need to use these methods no reload the instance with the related client. If you have HF EJB, pg 223 has the lifecycle diagram for both stateful and stateless session beans.


Patrick<br /> <br />SCJP/SCWCD/SCBCD/SCDJWS/SCEA<br /> <br />Currently working on:<br />SCJP 6
Balaji Anand
Ranch Hand

Joined: Nov 03, 2004
Posts: 146
I agree that the answers are b and f.
Raj, the stateless session bean never get a call to passivate and activate. they are there in the SessionBean just because there is only one common interface be it stateful or stateless.
Stateless session bean never gets passivated
I agree. Here's the link:
subject: Session Bean Doubt
It's not a secret anymore!