Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-30-2021 10:53 AM
In Spring Boot application I have configured 2 different transaction managers:
@Bean("jpaTransactionManager")
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
return transactionManager;
}
@Bean("neo4jTransactionManager")
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
Also, I have a separate services for PostgreSQL and Neo4j databases:
@Service("postgreSQLUserService")
@Transactional("jpaTransactionManager")
public class UserServiceImpl implements UserService {
@Autowired
private UserRepository userRepository;
@Override
public User create() {
return userRepository.save(new User());
}
.....
@Service("neo4jUserService")
@Transactional("neo4jTransactionManager")
public class UserServiceImpl implements UserService {
@Autowired
private UserRepository userRepository;
@Override
public User create() {
return userRepository.save(new User());
}
Separately such services work like expected and correctly communicate with PostgreSQl and Neo4j database. Right now I need to configure something like XA transactions. I need to be able in scope of one method to atomically create users in PostgreSQL and Neo4j database. In case one of the operation fail, I need also to rollback changes from another database, something like that:
@Transactional
public void createUser() {
postgreSQLUserService.create();
neo4jUserService.create();
}
I think, I may use Atomikos transaction manager in order to achieve it but don't know is it a right way. Could you please show an example how to configure XA transaction manager for such case?
UPDATED
Based on the following answer https://stackoverflow.com/a/57885706/1219755 looks like XA support was dropped from Neo4j... So the only way to implement such functionality is to implement Saga microservice pattern?
All the sessions of the conference are now available online