Skip to content

EclipseLink does not support read-only database connections [SPR-7891] #12547

Closed
@spring-projects-issues

Description

@spring-projects-issues

Florian Feigenbutz opened SPR-7891 and commented

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:

@Override
public ConnectionHandle getJdbcConnection(EntityManager em, boolean readOnly)
    throws PersistenceException, SQLException {
    AbstractSession session = (AbstractSession) getSession(em);
    // The connection was already acquired eagerly in beginTransaction,
    // unless lazyDatabaseTransaction was set to true.
    Connection con = session.getAccessor().getConnection();
    return (con != null ? new SimpleConnectionHandle(con) : null);
}

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();
    con.setReadOnly(readOnly);
    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?


Affects: 3.0.5

Issue Links:

7 votes, 8 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions