Enterprise JavaBeans - How to catch SQLException from a session bean

Hello

I have a stateless session bean which has a method to persist an entity (User) in the database. In User there is a foreign key (addressId) from another entity (Address). While i was persisting User, i entered a value of addressId which was not present in the Address table. Since there was a foreign key constraint on this field in User i got the following exception:

8:49:49,421 ERROR [JDBCExceptionReporter] ORA-02291:

integrity constraint (FK_USER_ADD) violated - parent key not

found 18:49:49,421 ERROR [AbstractFlushingEventListener]

Could not synchronize database state with session

org.hibernate.exception.ConstraintViolationException: could

not insert: [com.User] at org.hibernate.exception.SQLStateConverter.convert(SQLState

Converter.java:71)

So i placed the persist code inside a try block and was catching all the exceptions thrown by persist() method. But these exception are not caught. Instead the exception is sent to the Client end and printed on the client console.

Any clue on how to catch the ConstraintViolationException in the session bean?

Thanks

[1222 byte] By [rabbiaa] at [2007-11-26 23:14:50]
# 1
try catching Exception only. Will this error still occur?
clarenceloha at 2007-7-10 14:13:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
yes, i tried that as well but no luck. the catch block is completely ignored and the runtime exception goes to the client.thanks
rabbiaa at 2007-7-10 14:13:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...