code: @Override
      public ClassLoader getNewTempClassLoader() {
  
          return new ClassLoader(getClassLoader()) {  //NOSONAR
              /**
               * Searches for the .class file and define it using the current class loader.
               * @param className the class name
               * @return the class object
               * @throws ClassNotFoundException if the class cannot be found
               */
              @Override
              protected Class findClass(String className) throws ClassNotFoundException {
  
                  // Use path of class, then get the resource
                  String path = className.replace('.', '/').concat(".class");
                  URL resource = getParent().getResource(path);
                  if (resource == null) {
                      throw new ClassNotFoundException(className + " as resource " + path + " in " + getParent());
                  }
  
                  try {
                      ByteArrayOutputStream bout = new ByteArrayOutputStream();
                      IOUtils.copy(resource.openStream(), bout);
                      byte[] buffer = bout.toByteArray();
                      return defineClass(className, buffer, 0, buffer.length);
                  } catch (Exception e) {
                      throw new ClassNotFoundException(className + " as resource" + path + " in " + getParent(), e);
                  }
              }
  
              /**
               * Finds a resource in the bundle.
               * @param resource the resource
               * @return the url of the resource from the bundle, {@code null} if not found.
               */
              @Override
              protected URL findResource(String resource) {
                  return getParent().getResource(resource);
              }
  
              /**
               * Finds resources in the bundle.
               * @param resource the resource
               * @return the url of the resources from the bundle, empty if not found.
               */
              @Override
              protected Enumeration<URL> findResources(String resource) throws IOException {
                  return getParent().getResources(resource);
              }
  
          };
      }
docs: In this method we just create a simple temporary class loader. This class
  loader uses the bundle's class loader as parent but defines the classes
  in this class loader. This has the implicit assumption that the temp
  class loader is used BEFORE any bundle's classes are loaded since a class
  loader does parent delegation first. Sigh, guess it works most of the
  time. There is however, no good alternative though in OSGi we could
  actually refresh the bundle.
  
  @see javax.persistence.spi.PersistenceUnitInfo#getNewTempClassLoader()