I am confused about @Transactional annotation with base and subclasses. I have the following code with several generic subclasses derived from the base class CustomRepository<T> which implements ICustomRepository<T>. I want all the methods of the interface ICustomRepository<T> be transaction…
Tag: spring-transactions
Overriding transaction propagation levels for methods having Spring’s @transactional
I have multiple methods in my codebase annotated with Spring’s @transactional with different propgation levels (lets ignore the idea behind choosing the propagation levels). Example – Now I have a new use case where I want to perform all these operations in a single transaction (for this specific …
Data from test with @Transactional are persisting between tests
I have a small problem. I have started writing tests for my small project. The project uses SpringBoot, standard JpaRepository from Spring, as a testing framework I am using Spock and for testing the database, I’m using PostgreSQL container from TestContainers. The problem is, that data between tests is…
Not able to rollback DB changes in Aspect in Spring boot application
I have written one aspect around a service class. In the aspect, I am doing some operation in the before section, which I would like to be rolled back if some exception occurs in the enclosed service method. The service class is as follows: The aspect is as follows: I am seeing an exception in the service met…
SpringBoot – @Transactional – not opening transaction
I am trying to use transaction in SpringBoot app , for some reason it just doesn’t work. Below is the code for the sample app. I have a rest api in MyRestController.java which invokes DBService.hello() method. In hello() method I insert a row into a table using JOOQ. I see transaction is NOT being creat…
How to handle transactions with concurrent access in Spring
I have a service with one method: And I’m running Gatling with 2 parallel calls config with testModelId = 1L argument. As a result of these calls I’m getting error: What I can see from logs is that two calls have entered this method at once and each printed log I assumed that adding transaction an…