You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@aries.apache.org by "Christian Schneider (JIRA)" <ji...@apache.org> on 2016/01/18 10:19:39 UTC

[jira] [Comment Edited] (ARIES-1447) JPAWeavingHook transforming with wrong classloader

    [ https://issues.apache.org/jira/browse/ARIES-1447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15104988#comment-15104988 ] 

Christian Schneider edited comment on ARIES-1447 at 1/18/16 9:18 AM:
---------------------------------------------------------------------

I did some tests with hibernate 5 now in my tasklist-ds example:
https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-ds

The enhancement seems to work fine. Is this issue still relevant? I simply import the packages hibernate enhancement needs in my persistence bundle.

As far as I know the hibernate team also aims at providing a solution that does not need the imports. Not sure if this is already done.



was (Author: chris@die-schneider.net):
I did some tests with hibernate 5 now in my tasklist-ds example:
https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-ds

The enhancement seems to work fine. Is this issue still relevant?


> JPAWeavingHook transforming with wrong classloader
> --------------------------------------------------
>
>                 Key: ARIES-1447
>                 URL: https://issues.apache.org/jira/browse/ARIES-1447
>             Project: Aries
>          Issue Type: Bug
>          Components: JPA
>    Affects Versions: jpa-2.2.0
>         Environment: jpa 1.0.1
>            Reporter: Tuomas Kiviaho
>
> {{PersistenceUnitInfo}} has a {{getNewTempClassLoader}} which includes both provider and persistence unit classloader. The provider classloader is important when enhancing the class, but now the transformations is only done against persistence unit classloader that doesn't yet have needed the dynamic imports in place.
> As a workaround, I am mimicking the proper approach by using {{TempBundleDelegatingClassLoader}} in my patched version of {{WrappingTransformer}}
> BTW: The {{org.apache.aries.jpa.container.weaving.packages}} (that seems to be completely removed from 2.x???) could be replaced with ASM code that looks for referenced packages before and after transformation and adds the difference to dynamic imports. How I'm adding packages manually because the wildcard approach just doesn't seem right.
> {code:title=org/apache/aries/jpa/container/weaving/impl/WrappingTransformer.java }
> @@ -26,7 +26,9 @@
>  import javax.persistence.spi.ClassTransformer;
>  
>  import org.apache.aries.jpa.container.impl.NLS;
> +import org.apache.aries.jpa.container.unit.impl.TempBundleDelegatingClassLoader;
>  import org.osgi.framework.Bundle;
> +import org.osgi.framework.BundleReference;
>  import org.osgi.framework.Constants;
>  import org.osgi.framework.ServiceReference;
>  import org.osgi.framework.wiring.BundleCapability;
> @@ -35,6 +37,7 @@
>  
>  class WrappingTransformer implements ClassTransformer {
>    private final ClassTransformer delegate;
> +  private final ServiceReference<?> persistenceProvider;
>    private final Collection<String> packageImportsToAdd = new HashSet<String>();
>    
>    public WrappingTransformer(ClassTransformer delegate,
> @@ -48,6 +51,7 @@
>      }
>      
>      this.delegate = delegate;
> +    this.persistenceProvider = persistenceProvider;
>      
>      Object packages = persistenceProvider.getProperty("org.apache.aries.jpa.container.weaving.packages");
>      
> @@ -56,7 +60,7 @@
>          packageImportsToAdd.add(s);
>        }
>      } else {
> -      Bundle provider = persistenceProvider.getBundle();
> +      Bundle provider = persistenceProvider.getBundle(); 
>        String suffix = ";" + Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + "=" +
>        provider.getSymbolicName() + ";" + Constants.BUNDLE_VERSION_ATTRIBUTE 
>        + "=" + provider.getVersion();
> @@ -70,11 +74,25 @@
>  
>    public WrappingTransformer(ClassTransformer transformer) {
>      delegate = transformer;
> +    persistenceProvider = null;
>    }
>  
>    public byte[] transform(ClassLoader arg0, String arg1, Class<?> arg2,
>        ProtectionDomain arg3, byte[] arg4) throws IllegalClassFormatException {
> -    return delegate.transform(arg0, arg1, arg2, arg3, arg4);
> +    Bundle bundle = this.persistenceProvider.getBundle();
> +    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
> +    ClassLoader classLoader = bundleWiring.getClassLoader();
> +    BundleReference bundleReference = (BundleReference) arg0;
> +    bundle = bundleReference.getBundle();
> +    classLoader = new TempBundleDelegatingClassLoader(bundle, classLoader);
> +    Thread thread = Thread.currentThread();
> +    ClassLoader contextClassLoader = thread.getContextClassLoader();
> +    thread.setContextClassLoader(classLoader);
> +    try {
> +      return delegate.transform(classLoader, arg1, arg2, arg3, arg4);
> +    } finally {
> +      thread.setContextClassLoader(contextClassLoader);
> +    }
>    }
>    
>    public Collection<String> getPackagesToAdd() {
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)