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

EclipseLink does not support read-only database connections



    • Last commented by a User:


      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

      { 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();
      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?


          Issue Links



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


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