This is the first post. I think most of the posts are memorandums about what I stumbled upon at work. Be gentle. .. ..
Java 8 Spring Boot 1.5.14
Manage transactions with @Transactional and let DB (MySQL) perform update processing
The Service class is annotated with @Transational (readonly = true) In the method of that class
'''hogeRepository.save()
I was doing a save process like
Caused by: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
The transaction that throws the update process @Transational(readonly=false) You have to do it.
If @Transactional is given to both the class and the method, it will be overwritten with the one defined in the method.
Because transactions are not placed in unexpected places (such as adding methods) I thought it was not so good to give @Transactional to a class
https://dev.classmethod.jp/server-side/java/spring-nested-declarative-transaction/
In the method that I forgot to give @Transactional (readOnly = xxxx), After accessing the repository from the service and getting the data, If you get nested data with LazyLoad of JPA outside the method of the Service class A LazyInitializationException has occurred. Please note that LazyLoad, which loads late, will not work if it is outside the method.
Recommended Posts