Thanks for answering me. I read the link (spring documentation) and I found the following:
"However, the DAO throws a normal HibernateException (which is not flagged, so it does not need to be declared or caught), which means that callers can only handle exceptions as fatal - if they don’t want to depend on the Hibernate exception hierarchy. Elimination of certain reasons , such as an optimistic blocking failure, is not possible without a caller tied to an implementation strategy.This compromise may be acceptable for applications that are highly dependent on Hibernate and / or do not need special treatment except teachings. "
My DAO is based on the Plain Hibernate 3 API, so if I understand it correctly, my DAO only throws simple HibernateExceptions. They are uncontrollable and should not be billed or caught. If something goes wrong, with @Transactional the whole operation is rolled back.
To make sure that everything works as I expected it to work, I have to bind my DAO even closer to my application code. There I can check, for example, if the object is returned or not. (if null is else) I could also catch the exception, register it and tell the user that something went wrong and that his transaction did not work.
So, for now, I still think that - depending on the transaction: if I can work with the result, everything is fine - if not, I can tell the user.
when no transaction is specified to return the result, I can use try / catch to detect a HibernateException. But is the transaction still rolling back? I thought that catching a HibernateException avoids a transaction rollback. I still don’t know what to do .: - (
In addition to this, unfortunately, I do not understand what the MVC Exception Handling (@ExceptionHandler) is related to. There was a table of processed exceptions, but I did not find a HibernateException. Or do you think that it will work with this: @ExceptionHandler (HibernateException.classs)? You also said that you would not recommend handling exceptions this way.
nano7
source share