aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Exception handling in EJB3.0 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 "Exception handling in EJB3.0" Watch "Exception handling in EJB3.0" New topic
Author

Exception handling in EJB3.0

padma warlu
Greenhorn

Joined: Aug 17, 2005
Posts: 8
Hello,

I have written a small example in EJB3.0. This has got a simple session bean and an entity. Iam calling entitymanager.persist() in session bean business method to persist the data into database. But due to some problem, it got a runtime exception and displayed full stacktrace of that exception. I have try catch block in session bean business method and i have not given ex.printStackTrace() in catch, but still it is printing the full stacktrace. I think, it is being thrown by the toplink essentials. Do i need to configure anything in persistence.xml file? Is there anyway to not to print full stack trace whenever there is any exception. Rather i just need the short description of the error which i can get using ex.toString().

Iam using OC4J 10.1.3.3 as Application Server.

Pls help.
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
You are probably using a CMT session bean with a container-managed entity manager, so the exception would be happening at commit time, which is when the method has already completed. This would be why your catch block could not catch it. Try doing an em.flush() call from inside the session bean catch block. This will force your entity manager to write everything out immediately and give you a chance to catch the exception, if that is what you want to do.

I am not sure that I understand why you wouldn't want the full stack trace to be printed for a development-time error, but anyway...

There is no standard persistence.xml option in JPA, but there is an option in TopLink Essentials to control the stack trace being printed out. This is likely happening at the container level, though, so you would probably need to configure the logging in OC4J, which just uses java.util.logging by default, so you could customize it with handlers, etc, if you wanted to.


-Mike
Pro JPA 2: Mastering the Java Persistence API
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception handling in EJB3.0