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

How to distinguish System exception and application exception?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a mock question:
When a call is made to a single-entity find method in an entity bean, the
ObjectNotFoundException is thrown indicating that the requested entity was not found.
What happens to the transaction?(Select 1 correct choice)
a) It is automatically rolled back since it is an application exception.
b) It is not automatically rolled back since it is a system exception.
c) It is not automatically rolled back since it is an application exception.
d) It is automatically rolled back since it is a system exception.
e) It may or may not automatically rollback based on container specific implementation.

The correct answer is c).

Here are two problem confusing me:

1. How can I know a exception is System exception or Application exception? As ObjectNotFoundException, I really don't know it belong to which type.

2. In a transaction, does it really not roll back automatically when meeting a application exception? what happen when it meeting a SQL exception that is defind by developer(such as a exception included in store procedure)?

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

Originally posted by Along huang:
Here are two problem confusing me:

1. How can I know a exception is System exception or Application exception? As ObjectNotFoundException, I really don't know it belong to which type.

2. In a transaction, does it really not roll back automatically when meeting a application exception? what happen when it meeting a SQL exception that is defind by developer(such as a exception included in store procedure)?

best regards



(a) EJBException is a system exception and I would say all child classes of EJBException would fall under that category

(b) SQLException extends from Exception class. It is not a system exception and therefore it will not do the automatic rollback of the transaction when executing under an EJB Container. If you want to rollback the transaction then you will have to:

1. Either explicitly get the ejb context and call setRollBackOnly() method to notify the EJB container about the rollback.

2. OR translate the SQLException into an EJBException. This way you are converting an application exception into a system exception, which would cause the rollback.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Along,

If a RuntimeException or its subclass including EJBException is thrown out of EJB class under CMT, the transaction will be automatically rolled back. If you catch it and re-throw it, a rollback will happen. If you catch it and throw something else, then you'll need to call setRollbackOnly() to make a rollback happen.

If you're throwing your application exception as a result of, say, SQLException, you got to call setRollbackOnly().

With BMT, you control.

Shogo
 
Along huang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your direction!

In another scenario, during a transaction processing, the application suddenly crash.

In this case, if the transcation will be rocked back? if ture, what system process it? it is obvious that it is not application server because it have crashed. The only answer is database server, is it?

best regards
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic