Spring Framework
  1. Spring Framework
  2. SPR-5036

org.hibernate.jdbc.ConnectionWrapper visibility and OSGi

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.5.5
    • Fix Version/s: None
    • Component/s: Transaction
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      The following bug has been reported in the Spring-DM mailing list (sorry for the nasty copy paste).

      This is quite strange since Hibernate classloader is used for creating the session proxy so the ConnectionWrapper class should be visible.
      I assume the problem is fairly simple but deeply nested inside the stack.

      The original post is here: http://tinyurl.com/6jbm88

      > Caused by:
      > org.springframework.transaction.CannotCreateTransactionException:
      > Could not open Hibernate Session for transaction; nested except
      > ion is java.lang.IllegalArgumentException: interface
      > org.hibernate.jdbc.ConnectionWrapper is not visible from class loader
      > at
      > org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:
      > 599)
      > at
      > org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:
      > 377)
      > at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
      > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      > at java.lang.reflect.Method.invoke(Unknown Source)
      > at
      > org.springframework.osgi.service.importer.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:
      > 59)
      > at
      > org.springframework.osgi.service.importer.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:
      > 67)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:
      > 131)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:
      > 119)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.osgi.service.importer.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:
      > 36)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:
      > 59)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:
      > 131)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:
      > 119)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:
      > 204)
      > at $Proxy120.getTransaction(Unknown Source)
      > at
      > org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:
      > 263)
      > at
      > org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:
      > 101)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:
      > 204)
      > at $Proxy124.findLovNodeByName(Unknown Source)
      > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      > at java.lang.reflect.Method.invoke(Unknown Source)
      > at
      > org.springframework.osgi.service.importer.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:
      > 59)
      > at
      > org.springframework.osgi.service.importer.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:
      > 67)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:
      > 131)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:
      > 119)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.osgi.service.importer.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:
      > 36)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:
      > 59)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:
      > 131)
      > at
      > org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:
      > 119)
      > at
      > org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
      > 171)
      > at
      > org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:
      > 204)
      > at $Proxy67.findLovNodeByName(Unknown Source)

        Activity

        Hide
        Costin Leau added a comment -

        Just for the record, since this issue pops up from time to time, the issue raised over at the HB site is: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3529 (apparently it's not the only one).

        Show
        Costin Leau added a comment - Just for the record, since this issue pops up from time to time, the issue raised over at the HB site is: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3529 (apparently it's not the only one).
        Hide
        Bjorn Harvold added a comment -

        Developers who see this issue, go to Hibernate's Jira and vote on it.

        Show
        Bjorn Harvold added a comment - Developers who see this issue, go to Hibernate's Jira and vote on it.
        Hide
        Eric Jain added a comment -

        Is the workaround (adding "DynamicImport-Package: *" to the org.springframework.aop bundle manifest) still supposed to work in 2.5.6? Not working for me

        Show
        Eric Jain added a comment - Is the workaround (adding "DynamicImport-Package: *" to the org.springframework.aop bundle manifest) still supposed to work in 2.5.6? Not working for me
        Hide
        c added a comment -

        The "DynamicImport-Package: *" workaround does not work for me either. Is there any other solution to this problem?

        Show
        c added a comment - The "DynamicImport-Package: *" workaround does not work for me either. Is there any other solution to this problem?
        Hide
        Justin Griffin added a comment -

        I know this issue really belongs to Hibernate, but I had a similar problem and found a few workarounds.

        My first solution, I used an around advice to temporarily replace the calling thread's context class loader. I pointcut around my service that was calling hibernate. Here was my advice:

        public Object substituteClassLoader(ProceedingJoinPoint pjp) throws Throwable {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        try

        { return pjp.proceed(); }

        finally

        { Thread.currentThread().setContextClassLoader(contextClassLoader); }

        }

        My second solution (and the one I went with) works if you're using Spring-DM. You can use the "context-class-loader" attribute (http://static.springsource.org/osgi/docs/1.2.0/reference/html/service-registry.html#service-registry:export:ccl) when exporting your service.

        <service ref="myServiceImpl" interface="foo.bar.MyServiceInterface" context-class-loader="service-provider"/>

        This worked equally well, and has the added benefit of not having to code and wire your own AOP (nice work Costin and team)!

        To quote the Spring-DM docs: "The permissible values for the context-class-loader attribute are unmanaged (the default) and service-provider. When the service-provider value is specified, Spring Dynamic Modules ensures that the context class loader can see all of the resources on the class path of the bundle exporting the service."

        Hope this helps someone.

        Show
        Justin Griffin added a comment - I know this issue really belongs to Hibernate, but I had a similar problem and found a few workarounds. My first solution, I used an around advice to temporarily replace the calling thread's context class loader. I pointcut around my service that was calling hibernate. Here was my advice: public Object substituteClassLoader(ProceedingJoinPoint pjp) throws Throwable { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { return pjp.proceed(); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } } My second solution (and the one I went with) works if you're using Spring-DM. You can use the "context-class-loader" attribute ( http://static.springsource.org/osgi/docs/1.2.0/reference/html/service-registry.html#service-registry:export:ccl ) when exporting your service. <service ref="myServiceImpl" interface="foo.bar.MyServiceInterface" context-class-loader="service-provider"/> This worked equally well, and has the added benefit of not having to code and wire your own AOP (nice work Costin and team)! To quote the Spring-DM docs: "The permissible values for the context-class-loader attribute are unmanaged (the default) and service-provider. When the service-provider value is specified, Spring Dynamic Modules ensures that the context class loader can see all of the resources on the class path of the bundle exporting the service." Hope this helps someone.

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Costin Leau
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              4 years, 35 weeks, 5 days ago