Which statements about session beans are true? (Choose all that apply.)
(spec: 71)
A.
A stateful session bean is typically used to represent a row in a database
-that’s what entity beans do
B.
The client must call the ejbActivate method before calling any business methods.
-only the container calls ejbActivate()
C.
A stateful session bean’s fields can contain client conversational state.
D.
They are typically used as asynchronous message consumers.
Which list(s) correctly sequence some of the steps in a session bean’s lifecycle? (Choose all that apply.)
(spec: 77)
Which types of session bean instance fields can be successfully passivated and reactivated? (Choose all that apply.)
(spec: 71)
Which are valid remote component interfaces for a session bean? (Choose all that apply.)
(spec: 97)
A.
public interface MyBean extends javax.ejb.EJBObject { void myMethod(); }
- needs RemoteException
B.
public interface MyBean extends javax.ejb.EJBObject throws RemoteException { void myMethod(); }
-illegal Java !
C.
public interface MyBean extends javax.ejb.EJBHomeObject { void myMethod() throws RemoteException; }
- nope, gotta be EJBObject
D.
public interface MyBean extends javax.ejb.EJBObject { void myMethod() throws RemoteException; }
If a client makes a call to a session object that has been removed by the container, which exceptions can be thrown? (Choose all that apply.)
(spec: 79)
Given:
(spec: 98)
MyBean create(String name) throws CreateException, RemoteException;
Which session bean interface can contain this method?
What is true about a session bean’s lifecycle? (Choose all that apply.)
(spec: 79, 88)
A.
If a business method throws a system exception the bean will be passivated.
- no, the bean is killed
B.
A passivated bean must be activated before it can be removed.
- nope
C.
A stateless session bean’s removal must be initiated by the client not the container.
D.
Stateless session beans cannot implement the SessionSynchronization interface.
Which are required of the bean provider to ensure that a session bean is successfully passivated? (Choose all that apply.)
(spec: 71-72)
A.
The provider must call
ejbPassivate()
.B.
The provider must always add business logic to the
ejbPassivate()
method, if the bean is stateful.C.
The provider must not close any database connections before
ejbPassivate()
completes.D.
The provider must assume that any state stored in instance fields marked transient will be lost.
E.
The provider must assume that any reference to the SessionContext object will not survive passivation if the SessionContext object is not serializable.
Container MUST passivate your context, no matter what!
Given a stateless session bean with container-managed transaction demarcation, from which method(s) can you access another bean? (Choose all that apply.)
(spec: 90)
(Note: The real exam has several types of ‘drag and drop’ questions, that we’re going to do a lame job of simulating with this question...)
(API docs)
Match the methods on the left with the interfaces in which those methods can be found, on the right. A match is correct if the method is either declared in, or inherited by, the interface. Note: There may be some many-to-one and one-to-many relationships in your answer.
A.
afterCompletion
1
B.
getUserTransaction
2
C.
afterBegin
1
D.
isCallerInRole
2
E.
getRollBackOnly
2
F.
setSessionContext
3
G.
setRollbackOnly
2,4
SessionSynchronization
SessionContext
SessionBean
UserTransaction
What is true about a session bean’s lifecycle? (Choose all that apply.)
(spec: 70)
A.
The container will always create a new session bean instance when the client invokes the
create()
method on the home interface of a stateless bean.- Container makes stateless beans whenever it wants
B.
The container will always call
ejbRemove()
when the client invokes theremove()
method on a stateless bean’s home interface.- Container removes a stateless bean ONLY when it wants to shrink the pool
C.
A session bean cannot be passivated while it is in a transaction.
D.
The
setSessionContext()
method is not invoked during a stateless bean’s lifecycleWhich of the following methods are container callback methods? (Choose all that apply.)
(spec: 73)
In what case(s) will the container fail to call ejbRemove() on a session bean? (Choose all that apply.)
(spec: 82)
Which method(s) allow both stateful and stateless session beans with bean-managed transaction demarcation to access UserTransaction methods? (Choose all that apply.)
(spec: 80, 90)
For which type of bean can the container passivate an instance that is in a transaction?
(spec: 70)
For session beans, which are the responsibility of the Container? (Choose all that apply.)
A.
Invoking the local interface
create()
method.- client calls it
B.
Invoking the
getSessionContext()
method.- Container calls setSessionContext
C.
Invoking the
ejbCreate()
method.D.
Ensuring that the
ejbRemove()
method is always invoked.- might be missed if passivated bean times out, or bean throws a runtime exception
For this drag and drop type question, you can use each element only once. Which interface should be matched with which fact, so that all four matches are correct?
1.
remote component
b
2.
remote home
a
3.
local component
c
4.
local home
d
Has a
getHomeHandle()
methodextends
'javax.ejb.EJBObject'
methods must NOT throw
'java.rmi.RemoteException'
can be used to retrieve an EJBLocalObject
Which can be called by the container during the lifecycle of a session bean? (Choose all that apply.)
(spec: 90, 97)
Which statements about a session bean class are true? (Choose all that apply.)
(spec: 95)
For which type of bean can the SessionSynchronization interface be implemented?
Which statements are true for stateless session bean instances? (Choose all that apply.)
(spec: 88)
Get Head First EJB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.