Affects: \Spring framework 5.1, Spring boot - 2.1.1.RELEASE
I have a use case to use Mongo transactions. For enabling transactions i followed the mongo transaction document In my application I have MySql DB connections as well.
Upon creating the mongo transaction bean, the JPA repositories save() method is not persisting data.
The JPA repositories save method works well, if I comment out MongoTransactionManager bean:
public class MongoTransactionConfiguration extends AbstractMongoConfiguration {
@Autowired
private MongoProperties props;
/* @Bean
MongoTransactionManager transactionManager(MongoDbFactory dbFactory) {
return new MongoTransactionManager(dbFactory);
}*/
@Override
public MongoClient mongoClient() {
return new MongoClient(new MongoClientURI(props.getUri()));
}
@Override
protected String getDatabaseName() {
return props.getDatabase();
}
}
The sample code is available in github In this example I'm connecting to local host mysql, and as part of @PostConstruct of Application class, will try to populate a table.
The table gets populated when mongo transaction bean does not exists. But when the MongoTransactionBean exists nothing gets populated.
I expect to have MongoTransactions enabled and proper functioning of mysql save(). Could someone help me figure out how to overcome this issue?
Stackoverflow : https://stackoverflow.com/questions/56424920/mongo-transactions-manager-bean-presence-alters-behaviour-of-save-for-jpa-repo
Comment From: snicoll
I can see someone answered you on StackOverflow.