Two Laptop Bag
The moose likes EJB and other Java EE Technologies and the fly likes Handling database exception in CMP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Handling database exception in CMP" Watch "Handling database exception in CMP" New topic

Handling database exception in CMP

Greg Charles

Joined: Oct 01, 2001
Posts: 2969

We have a stateless session bean acting as a facade for CMP entity bean. Our container is WebLogic 8.1 and our database is Oracle 9i. What happens is a remote client calls a method on the session bean, which starts a transaction. This method then calls a set method on the CMP using the same transaction. However, there is a unique constraint on this field in Oracle, so occasionally Oracle can object to the value that was set. This is formed into a SQLException, but it's not thrown by the CMP's setter, since it doesn't actually occur until the container stores the new value. In fact, it can't be caught by the session bean at all. When the transaction tries to commit, WebLogic wraps the SQLException in a Runtime "unexpected" exception and throws it back to the original client.

My question: is there any way we can catch this in the session bean so we can report the error more clearly back to the client? Thanks!
I agree. Here's the link:
subject: Handling database exception in CMP
It's not a secret anymore!