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

Spring's JDBC connection access disables shared cache in EclipseLink

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 4.1.1
    • Fix Version/s: 4.1.2
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      In the EclipseLinkJpaDialect Spring does the following,

      @Override
      public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
      throws PersistenceException, SQLException, TransactionException {

      super.beginTransaction(entityManager, definition);
      if (!definition.isReadOnly() && !this.lazyDatabaseTransaction)

      { // This is the magic bit. As with the existing Spring TopLink integration, // begin an early transaction to force EclipseLink to get a JDBC Connection // so that Spring can manage transactions with JDBC as well as EclipseLink. UnitOfWork uow = (UnitOfWork) getSession(entityManager); uow.beginEarlyTransaction(); }

      // Could return the UOW, if there were any advantage in having it later.
      return null;
      }

      This is done to force EclipseLink to read through a transactional connection, so that it can see changes made directly through JDBC. But it has the side-affect of effectively disabling the shared cache in EclipseLink.

      EclipseLink will no longer cache any objects read because a transactional connection is being used.

      Which connection is used is configurable in EclipseLink by the user, so Spring should not be forcing any setting on the user, and not be using an internal API to do it.

      The correct way to enable this is either to set the persistence unit property,
      "eclipselink.jdbc.exclusive-connection.mode"="Always" (will allow a shared cache)

      or
      "eclipselink.transaction.join-existing"="true" (does not allow a shared cache)

      If Spring desires different functionality than the EclipseLink defaults (not sure it should), then it should just default these properties if they have "not" already be configured by the user. This would allow the user to choose if they want caching to work or not.

      Otherwise just remove this code and let the user configure if they wish to allow caching or not.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              jamesssss James Sutherland
              Last updater:
              Spring Issues Spring Issues
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 31 weeks, 2 days ago