I am getting this error when I am putting this piece of code on a service method
@Transactional(readOnly =true)
I am writing this code to make a transaction read only. Can you please tell me What I did wrong in this case
Spring @Transactional annotation The readOnly attribute can further be used by Spring to optimize the underlying data access layer operations. Prior to Spring 5.1, when using Hibernate, the readOnly attribute of the @Transactional annotation was only setting the current Session flush mode to FlushType.
A read-only transaction or query is a transaction which does not modify any data.
The @Transactional annotation is the metadata that specifies the semantics of the transactions on a method. We have two ways to rollback a transaction: declarative and programmatic. In the declarative approach, we annotate the methods with the @Transactional annotation.
Annotation Type Transactional. Describes a transaction attribute on an individual method or on a class. When this annotation is declared at the class level, it applies as a default to all methods of the declaring class and its subclasses.
Make sure you import @Transactional
from org.springframework.transaction.annotation.Transactional
and not from javax.transaction.Transactional
as readOnly
attribute is specific to Spring transaction.
Add
import org.springframework.transaction.annotation.Transactional;
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