• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing Mistake on Practice questions -HFEJB

 
Joy Mookerji
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have came accross an error on the practice questions of Chapter 4 of HFEJB

Question No 8
Which is required of the bean provider to ensure that a session bean is successfully passivated ? (Choose all that apply)

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 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 be not survive passivation if the SessionContext object is not serializable.


As per my understanding correct answer will be

c) and d)

However here are the answers

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 ----NOTICE THE NOT HERE

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 be not survive passivation if the SessionContext object is not serializable.

Answer d)

Either the not is missing in question or not should not be present in the answer and answer will be c and d

Any suggestions is appreciated
 
cheenu Dev
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right..
c and d.
but in d..there is no "not" missing..it is correct.
 
Charlie A
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joy..

I feel the answer mentioned in the HFEJB is correct; i.e. answer - d only

Option C is bit tricky, you need to interpret it carefully.

c) The provider must close any database connections before ejbPassivate() completes.

Thumb Rule :
The Stateful session bean will successfully passivated if we ensure that all the non-transient variables must one of the following -
1. Serializable Object
2. a null value
3. bean's remote component interface or home interface
4. bean's local component or home interface
5. a SessionContext Object
6. Object of type JNDI Context
7. UserTransaction interface type
8. Resource manager connection Factory (like javax.sql.DataSource instance)


Closing the database in option C, implies something like conn.close();
It is good to call the clean up methods in the methods ejbPassivate() and ejbRemove(), but it is not a MUST. Here the option C fails..

I hope this might have cleared your doubt.
 
Joy Mookerji
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charlie,
Pls see the Ejb-2.1 spec

Section 7.4.1 Instance Passivation and Conversational State

Its mentioned

"This means for example,that the Bean Provider must closee all JDBC connections in ejbPassivate and assign instance fields storing the connection to null"
 
Charlie A
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joy,

You are right

The question is missing the word 'not'.. Good Catch!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic