• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with a mock-question in Paul Sangheras book

 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

there is the following mock-question in the book from Paul Sanghera on page 121:

In which of the following cases will the container remove a session bean instance without invoking the ejbRemove() method?

a) The bean instance throws a system exception.
b) The bean instance in a passive state times out.
c) The bean instance in the method ready state times out.
d) The bean instance calls a prohibited method of its session context.
e) The client invokes the method remove().

Pauls answer: A, B

But why is option d) wrong? When a bean instance calls a prohibited method of its session context, an IllegalStateException will be thrown. This is a RuntimeException. A RuntimeException is a system exception, and when the bean instance throws a system exception, the container will remove the bean instance without invoking the ejbRemove() method.

Is my conclusion true or false?

Regards,
Oliver
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently this issue has already been raised on the books support forum see Review Question #6, Chapter 5 has another correct response.

When in doubt, refer to the spec:EJB 2.0 Spec.

Now Paul's being a bit coy with his response in traditional instructor fashion (think Padawan, think). But I think the essence is that answer (d) may lead to the session bean's removal but it doesn't have to. When calling the prohibited method the container throws the exception. The bean method responsible for calling the prohibited method receives that exception. Options:
  • The method ducks the exception and it escapes outside of the bean - the bean is toast.
  • The method handles the exception and doesn't throw a new one. The bean lives.

  • So (d) is a maybe. But the question asks for "In which of the following cases will the container remove a session bean instance without invoking the ejbRemove() method?".
     
    Oliver Rensen
    Ranch Hand
    Posts: 109
    Eclipse IDE Firefox Browser Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Peer, thanks a lot for your help to clarify this misleading question.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic