Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The attribute readOnly is undefined for the annotation type Transactional

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

like image 572
Vipul Jain Avatar asked Aug 19 '15 05:08

Vipul Jain


People also ask

What does the Read-Only attribute in @transactional annotation do?

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.

What is readOnly in transactional?

A read-only transaction or query is a transaction which does not modify any data.

What is the @transactional annotation?

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.

What is use of @transactional annotation in Spring boot?

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.


2 Answers

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.

like image 133
Bnrdo Avatar answered Oct 17 '22 12:10

Bnrdo


Add

import org.springframework.transaction.annotation.Transactional;

like image 2
Arun Avatar answered Oct 17 '22 12:10

Arun