Given the following scenario:
I have an app running with Spring Boot @SpringBootApplication
and setup with Spring Data JPA datasource in application.properties
:
spring.datasource.url=jdbc:mysql://foo.bar.com:12345
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
and no additional java/xml configs.
I have a couple of services:
@Service
public class ProjectServiceImpl implements ProjectService {
@Autowired
ProjectRepository projectRepository;
@Override
@Transactional(isolation = Isolation.SERIALIZABLE)
public Project save(Project project) {
// there might be some additional logic here, besides the action on repository
return projectRepository.save(project);
}
}
and repositories:
@Repository
public interface ProjectRepository extends CrudRepository<Project, Long> {}
As it's in the code above, I found myself in need of, let's say, SERIALIZABLE
level of isolation due to the app being scaled up horizontally and occasionally saving conflicting data to DB (simply @Transactional
was no enough). Now, when trying I try to perform projectService.save(project)
action I get an exception:
"exception": "org.springframework.transaction.InvalidIsolationLevelException",
"message": "JtaTransactionManager does not support custom isolation levels by default - switch 'allowCustomIsolationLevels' to 'true'",
Is it possible to enable those custom isolation levels with a java config?