JavaBlog.fr / Java.lu Java,Spring Spring: Transaction management with checked, unchecked exceptions

Spring: Transaction management with checked, unchecked exceptions

Often, developers forgotten the transactional behaviour of proxies Spring:
– by default, the transaction is rollbacked only in the case of runtime, unchecked exceptions (an instance or subclass of RuntimeException) and for Errors;
– the transaction is not rollbacked if a checked exception is thrown from a transactional method.

A good practice is to create 2 types of checked exceptions extending Exception:
– one for the rollback needs for example “BusinessMessageException extends Exception”,
– an other for the no-rollback needs for example “BusinessMessageExcWithoutRollback extends BusinessMessageException”,

and modify the transaction parameters of classes with

"@Transactional(readOnly = true, rollbackFor=BusinessMessageException.class)"

and depending on needs, the parameters of each transactional method with:

"@Transactional(readOnly = false, propagation = Propagation.REQUIRED, noRollbackFor=BusinessMessageExcWithoutRollback.class)"

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

Related Post

Documentum : BOF – SBO (Service based Business Object) – NoSuchMethodException – JAVA reflectionDocumentum : BOF – SBO (Service based Business Object) – NoSuchMethodException – JAVA reflection

Hello, After my previous post http://www.javablog.fr/documentum-bof-sbo-service-based-business-object-tbo-type-based-business-object-aspects.html, just a mini post related an error java.lang.NoSuchMethodException which occurs when the use of a SBO’s method whereas it exists. Basically in JAVA, the