Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-20800

Remove unneeded extra Persistence container calls to AbstractEntityManager.getEntityManager()

XMLWordPrintable

    • ---
    • ---

      Remove two unneeded calls to https://github.com/wildfly/wildfly/blob/1f68b0ad54b7899650a782a8efdde0cec196865c/jpa/subsystem/src/main/java/org/jboss/as/jpa/container/AbstractEntityManager.java#L50

      https://github.com/wildfly/wildfly/blob/1f68b0ad54b7899650a782a8efdde0cec196865c/jpa/subsystem/src/main/java/org/jboss/as/jpa/container/AbstractEntityManager.java#L487 contains an extra call to getEntityManager():

      public <T> T find(Class<T> entityClass, Object primaryKey) {
              long start = 0;
              if (isTraceEnabled)
                  start = System.currentTimeMillis();
              try {
                  final EntityManager underlyingEntityManager = getEntityManager();
                  T result = getEntityManager().find(entityClass, primaryKey);
                  detachNonTxInvocation(underlyingEntityManager);
                  return result;
              } finally {
                  if (isTraceEnabled) {
                      long elapsed = System.currentTimeMillis() - start;
                      ROOT_LOGGER.tracef("find entityClass '%s' took %dms", entityClass.getName(), elapsed);
                  }
              }
          }
      

      https://github.com/wildfly/wildfly/blob/1f68b0ad54b7899650a782a8efdde0cec196865c/jpa/subsystem/src/main/java/org/jboss/as/jpa/container/AbstractEntityManager.java#L147 also contains an extra call to getEntityManager():

          public <T> T getReference(Class<T> entityClass, Object primaryKey) {
              long start = 0;
              if (isTraceEnabled)
                  start = System.currentTimeMillis();
              try {
                  final EntityManager underlyingEntityManager = getEntityManager();
                  T result = getEntityManager().getReference(entityClass, primaryKey);
                  detachNonTxInvocation(underlyingEntityManager);
                  return result;
              } finally {
                  if (isTraceEnabled) {
                      long elapsed = System.currentTimeMillis() - start;
                      ROOT_LOGGER.tracef("getReference entityClass '%s' took %dms", entityClass.getName(), elapsed);
                  }
              }
          }
      

      In both cases the second call to getEntityManager() should be replaced with underlyingEntityManager.

              smarlow1@redhat.com Scott Marlow
              smarlow1@redhat.com Scott Marlow
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: