is there any difference between:
Using spring and Hibernate ?
The @Transactional annotation makes use of the attributes rollbackFor or rollbackForClassName to rollback the transactions, and the attributes noRollbackFor or noRollbackForClassName to avoid rollback on listed exceptions. The default rollback behavior in the declarative approach will rollback on runtime exceptions.
By using @Transactional , many important aspects such as transaction propagation are handled automatically. In this case if another transactional method is called by businessLogic() , that method will have the option of joining the ongoing transaction.
So when you annotate a method with @Transactional , Spring dynamically creates a proxy that implements the same interface(s) as the class you're annotating. And when clients make calls into your object, the calls are intercepted and the behaviors injected via the proxy mechanism.
transaction. Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans, as well as classes defined as managed beans by the Java EE specification, at both the class and method level where method level annotations override those at the class level.
Basically, if you annotate the class with @Transactional
all methods will be transactional.
If you don't, you can annnotate as @Transactional
only those methods you want to. Additionally, you can specify different attributes for each method, like isolation
, propagation
, timeout
, ...
Also, take a look at this question, this is a possible duplicate of it: Hibernate transaction annotations in source — difference between class and method level use?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With