• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on exceptions

 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


It has no descriptor. A client makes a call to oops, which runs in the context of the client's transaction. What action would you expect the container to perform, if any, after this transaction is thrown?

A) The exception is rethrown.
B) An EJBException is thrown by the container to the client.
C) It discards the instance of the session bean.
D) It performs some actions and eventually executes the slashstar method.
E) It is the responsibility of the bean provider to properly catch and handle such exceptions.

Besides the fact that the question is somewhat weird (I don't think you can "throw" a transaction ) the answer is to be said "C" (there is only one answer correct)

Now, as far as I know the PersistenceException is a normal RuntimeException, so its considered to be a System Exception and is therefore wrapped with an EJBException... but B) is not correct. Is there something I'm missing here ?
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim,

The answer A it looks ok also, the PersistenceException is wrapped in to a EJBException and rethrow - but it does not reach the client.
I think that the A and C are correct (even if the C is very strange formulated).

Regards,
M
 
Jim Janssens
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see what you mean, but you must look at it as being the container.
The question states "what action will the container do".

So, if you say A), it would mean the containers re-throws the PersistenceException and that is NOT the case. The container wraps the persistence exception and then throws a EJBException to which this persistenceexception is chained (so its not retrhowing the same PersistenceException as thrown from the business code)

Anway, the correct answer was ONLY C). There were only radio buttons, no checkboxes. I got this question from the free sun assesment questions on SCBCD. I find it weird since the solution to this question should be C) AND B)

I tested on JBOSS and my client does get a EJBException with the PersistenceException chained. So option B) is also correct stating that the container will wrapp the original PersistenceException in an EJBException that is then thrown to the client.

EDIT

Now that I think of it, maybe its in the small details here.
B) does not say anything about 'wrapping' the PersistenceException with a EJBException. So its probably not 100% complete and thereby not valid as answer. The container does throw an EJBException, but wrapping the original PersistenceException and that is not mentioned in the answer. Anyway, I hope the real exam is more clear on these kind of things
[ December 30, 2008: Message edited by: Jim Janssens ]
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Persistence Exception is a runtime exception, and hence a system exception. Hence the EJB instance will be discarded for sure...so C is correct..
and since the client had started the transaction, he'll get "EJBTransactionRolledbackException", which is a subclass of EJBException..
So in a way, even B is correct...

Rahul Babbar
 
Jim Janssens
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul Babbar wrote:Persistence Exception is a runtime exception, and hence a system exception. Hence the EJB instance will be discarded for sure...so C is correct..
and since the client had started the transaction, he'll get "EJBTransactionRolledbackException", which is a subclass of EJBException..
So in a way, even B is correct...

Rahul Babbar



Hmm, I overlooked the transaction thing.

This might as well be the solution to the problem, since EJBTransactionRolledbackException is only thrown if the client is local
For a remote client the javax.transaction.TransactionRolledbackException is thrown.

You cannot distinguish if this session bean has a local or remote interface.
It looks like you can, since the bean has no remote/local annotation and only implements one interface -> default to the single interface being local
However you cannot be sure that the interface itself has no remote annotation...

So considering this, option B might be correct but there is not enough information.

The only valid solution is then indeed C
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jim Janssens wrote:

This might as well be the solution to the problem, since EJBTransactionRolledbackException is only thrown if the client is local
For a remote client the javax.transaction.TransactionRolledbackException is thrown.



Are you sure about this?
can you please provide the reference for the above info.

Rahul Babbar
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul Babbar wrote:can you please provide the reference for the above info.


Check "14.3.1 Exceptions from a Session Bean’s Business Interface Methods" of the core specification. (and note [D])
 
reply
    Bookmark Topic Watch Topic
  • New Topic