3 Replies Latest reply on Aug 1, 2005 5:01 AM by jonefun

    JBoss 4.0.2 EJB3 Problem catching exception while persisting

    jonefun Newbie

      I'm using JBoss 4.0.2 with EJB 3.0 support on Firebird 1.5 database.

      I intended to place a unique constraint on the Email field of my Customer entity so that I can catch instances where two users attempt to register with the same Email address. My first plan was to do a search before I attempted an insert but then I thought a nicer way would be to put a unique constraint on the Email field of the Customer entity and then catch the Unique constraint exception as part of the normal logic etc.

      I have an entity with a field marked as Unique and I insert the same data twice to force a unique constraint exception. The problem is that when I attempt to persist the second entity with the duplicate data the EntityManager does not actually throw an exception ( well it doesn't throw it in my SFSB class anyway )

      When I check the JBoss output I can see the exception being caught by the JDBCExceptionReporter, AbstractFlushingEventListener (obviously running as part of the JBoss TransactionManager and on another thread than my SFSB ) and it is being thrown, but it appears that the JBoss implementation of the EntityManager does not actually throw the error and therefore my statefull session bean that is attempting to persist the entity is not aware of the problem.

      Obviously the insert fails and the transaction attempts to rollback but I would like to know about the failure in my session bean so that I can take appropriate action.

      To summarise :-
      1. Create an Entity with a field that has Unique constraint
      2. Create a SFSB that has a CreateCustomer method
      3. Create a client that calls the SFSB twice with the same data

      Problem :-
      1. The SFSB does not recieve any kind of Exception as a result of the failed insert
      2. JBoss (JDBCExceptionReporter ) catches and logs the JDBC Error
      3. The error while captured by the Application Server is never passed to SFSB
      4. The Transaction is automatically rolled back even though it is a valid error and continuation is acceptable

      If anybody can help me with this I would be very appreciative

      Thanks for any help you can give

      Cheers

      Jonathan