We are migrating from the MySQL connector to the MariaDB connector. We are using Spring and the Bitronix transaction manager.
When we changed connector, we are facing several issues with transactions. Probably we have found the root cause: differences between handling joined transactions with MySQL and Maria, please see details below:
We are using this annotation on several places in the project:
@Transactional(propagation = Propagation.REQUIRES_NEW)
Here is the differences in implementation:
MySQL connector, MysqlXAConnection#isSameRM implementation:
if(xaresinstanceofMysqlXAConnection){
return this.underlyingConnection.isSameResource(((MysqlXAConnection)xares).underlyingConnection);
}
MariaDB connector, org.mariadb.jdbc.MariaXaResource#isSameRM implementation:
//Typicallyusedbytransactionmanagerto"join"transactions.Wedonotsupportjoins,
//soalwaysreturnfalse;
return false;
Is there someone who faced the same issue? How to handle it?
Our implementation:
/**
* Implementation of Audit Log which saves data using JPA in new transaction.
*/
public class JpaAudit implements AuditSPI {
@Autowired
private AuditlogRepository auditLogRepository;
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void log(AuditLogEntity aAuditObj) {
auditLogRepository.save(aAuditObj);
}
}
Changing Propagation.REQUIRES_NEW
to Propagation.REQUIRED
helps but I think it is not way for us.
The issue in your question was reported (CONJ-825) and corrected (commit 70c406b2) by Diego Dupin (thanks to him).
The main part of the commit is in src/main/java/org/mariadb/jdbc/MariaXaResource.java :
@Override
public boolean isSameRM(XAResource xaResource) {
- // Typically used by transaction manager to "join" transactions. We do not support joins,
- // so always return false;
+ if (xaResource instanceof MariaXaResource) {
+ MariaXaResource other = (MariaXaResource) xaResource;
+ return connection
+ .getProtocol()
+ .getUrlParser()
+ .equals(other.connection.getProtocol().getUrlParser());
+ }
+ return false;
}
This fix is included from MariaDB Connector/J 2.7.0.