File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Handle exception in Facade Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Handle exception in Facade" Watch "Handle exception in Facade" New topic

Handle exception in Facade

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342

My client is a SWT client and the server expose stateless session beans as facade.

i want to consult with you about handling excpetions:

1.Commit is called after the facade method was ended, so in case that the commit was failed due to database integrity the facade will not catch this excpetion and this excepytion will be thrown to the client without the ability to handle this exception? how do you solve this issue in your facades? you think that in the facade i should catch all exception and call to roleback in case of exception. a good reason for this is that the client can get a ClassNotFoundException in case that the Exception class in not in is classpath
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

I think the code that handles the commit should handle the rollback. Does the transaction cross multiple session bean calls? If not, the database has some tables/data locked for longer than necessary.

You can define your own checked exception and put it in your method signature. That would guarantee the client has it in the classpath.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
I dont have a code to handle the commit.
The facade is stateless session bean (CMT = Container managed transaction), so the transaction commited in the end of the method.
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153

You stateless session bean should throw a RemoteException which you could catch on the SWT side just to display a user friendly exception.

If you want to handle the error on the server side just create a new method that actually has all the business logic and encapsulate it with your current business method. You should be able to catch Exceptions on your EJB later and send some user-friendly message to the client.

Shailesh Kini.
I agree. Here's the link:
subject: Handle exception in Facade
jQuery in Action, 3rd edition