gavin wrote:
HibernateExceptions should certainly not be application exceptions because ... well ... they have nothing to do with "application".
They should be runtime, so that they force txn rollback.
Gavin,
I support your statement about HibernateExceptions when they represent low-level problems with the datastore or the mapping mechanism. Such exceptions are probably caused by infrastructure malfunctions or development bugs and are therefor useless for a client. They can smoothly be converted to a RemoteException or EJBException (by the EJB container).
On the other hand, i assume some HibernateExceptions can be usefull for a client. Particulary the constraint-violation-specific subclasses of JDBCException (e.g. representing a Unique Constraint) are sometimes usefull since they represent a recoverable problem which should be handled by the client (and which are for performance reasons not already validated in code). These exceptions shouldn't be converted to a RemoteException or EJBException (since it's not the responsability of the client to inspect the cause of this RemoteException).
I'm aware of the
evilness of checked exceptions and I'm not advocating to re-introduce them (EJB3s EM will also throw unchecked exception) but I'm looking for a way to convert some HibernateExceptions in some cases to checked application exceptions (which will also mark the tx for rollback). My solution was to write a wrapper around the Hibernate Session which transforms the Hibernate exception into the correct application exception but this only works for the operations which are implicily called on the session and (I assume) not for the dirty checking mechanism. Correct?
- Is it possible to intercept the runtime exception which will be thrown when the first level cache gets synchronised with the DB => when the transaction commits (if the CMT was started on the session facade, the control will be already given back to the container)?
- What is your view on this kind of exception handling, based on your experience with Hibernate and in the EJB 3 expert group?
Thanx in advance,
Stijn Janssens