Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7891

EclipseLink does not support read-only database connections

    XMLWordPrintable

    Details

    • Last commented by a User:
      true

      Description

      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?

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              florian.feigenbutz Florian Feigenbutz
              Last updater:
              Spring Issues Spring Issues
              Votes:
              7 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Days since last comment:
                3 years, 18 weeks, 6 days ago