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

