Reputation: 142
I know that hibernate will rollback all the changes made inside a @Transactional annotated method if any exception occurs inside it.
I am also aware that if we handle the exception with try catch then hibernate won't perform transaction rollback operation.
My question is that will hibernate perform transaction rollback if I handle the exception with try catch from the caller method (The method which invoked the database update operation method annotated with @Transactional)??
Upvotes: 0
Views: 5115
Reputation: 142
Well after testing it out myself I found out that even if you handle an exception from the caller method the transaction will roll back.
If anyone wondering what will happen if the caller method itself has transactional annotation in it? It will throw this exception:
org.springframework.transaction.UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only
The reason for it is explained in this answer
Upvotes: 2