Closed suiheyu closed 5 months ago
Good catch.
I fixed it with https://github.com/spring-projects/spring-data-jpa/pull/3194, test case added to guard that all modifying methods are annotated with @Transactional
.
ok ,thanks
That has been fixed via #3499
In my work, I have been using the convenient features provided by Spring Data JPA's JpaRepository for rapid development. However, when I attempted to call the following code for the first time, it resulted in a java.sql.SQLException.
import java.util.List;
@Repository public interface JpaResourceOwnershipRepository extends ListCrudRepository<ResourceOwnershipPO, String>, JpaSpecificationExecutor {
}
The exception message "Connection is read-only. Queries leading to data modification are not allowed" indicates that a read-only transaction is in effect, even though you didn't explicitly declare any "read-only transactions" in your business code. Upon investigation, I discovered that Spring Data JPA, specifically within the
org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor.RepositoryAnnotationTransactionAttributeSource#computeTransactionAttribute
method, obtainsTransactionAttribute
based on certain priorities. By default, it first checks whether yourJpaResourceOwnershipRepository
methods and classes have relevant transaction annotations. Then, it looks at the declarations in Spring Data JPA'sSimpleJpaRepository
class. Subsequently, I reviewed the source code for the corresponding method inSimpleJpaRepository
. Please see the following code snippet: