We are using Spring and EclipseLink to establish two separated connection pools to replicated MySQL systems.
One connection pool contains "write" connections and should interact with the MySQL master only. The other connection pool contains "read" connections addressing the MySQL slaves.
These pools are established using EclipseLink's connection pool implementation and the MySQL replication driver.
This driver decides whether to address the MySQL master or slave host(s) based on the connection's "readOnly" attribute. Connections having "readOnly=true" will be executed on any of the configured slaves while "readOnly=false" will address the MySQL master system.
We use the Transactional annotation in order to control whether our methods should make use of read or write connections, e.g.:
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
Unfortunately the annotation's "readOnly" attribute is never transformed into read-only database connections in our environment.
It seems as if the EclipseLinkJpaDialect is missing to set this attribute in the getJdbcConnection method:
public ConnectionHandle getJdbcConnection(EntityManager em, boolean readOnly)
throws PersistenceException, SQLException
Calling the connections's setReadOnly method would fix the issue and enable the MySQL replication driver to address the correct DBMS:
Connection con = session.getAccessor().getConnection();
return (con != null ? new SimpleConnectionHandle(con) : null);
Could this be a Spring bug or are we missing anything in our application configuration?
Is there any reason why the current getJdbcConnection implementation ignores the present "readOnly" argument?