2 Replies Latest reply on May 3, 2012 1:13 AM by Mike Toggweiler

    ClassNotFoundException of Javassist Proxy class when serializing uninitialized lazy loaded fields

    Mike Toggweiler Newbie

      When using a Remote service from within an EJB and serializing hibernate models with lazy-uninitialized model state we get a ClassNotFoundException of the following form:


      Caused by: java.lang.ClassNotFoundException: ch.metas.soa.prototyping.jboss.marshalling.models.BookShelf_$$_javassist_2 from [Module "deployment.ear2.ear:main" from Service Module Loader]

      12:14:28,334 ERROR [stderr] (EJB default - 8)     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

      12:14:28,335 ERROR [stderr] (EJB default - 8)     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

      12:14:28,335 ERROR [stderr] (EJB default - 8)     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

      12:14:28,335 ERROR [stderr] (EJB default - 8)     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

      12:14:28,335 ERROR [stderr] (EJB default - 8)     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

      12:14:28,336 ERROR [stderr] (EJB default - 8)     at java.lang.Class.forName0(Native Method)

      12:14:28,336 ERROR [stderr] (EJB default - 8)     at java.lang.Class.forName(Class.java:264)

      12:14:28,336 ERROR [stderr] (EJB default - 8)     at org.jboss.marshalling.cloner.ClassLoaderClassCloner.clone(ClassLoaderClassCloner.java:46)

      12:14:28,336 ERROR [stderr] (EJB default - 8)     at org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:158)



      The problem is not the serialization at al because the javassist LazyInitializer creates a SerializableProxy itself. But after serializing the object to the remote service the object gets cloned. And this clone mechnism doesn't support cloning of dynamically generated proxy through javassist.


      The attached example demonstrates the problem and a possible 'solution' to it. We use the following maven projects

      - demo_client calls Service from ear2/ejb2

      - ear2/ejjb2 contains a simple proxy service which redirects request to ear1/ejb1

      - ear1/ejb1 contains two services, a simple service returning lazy initialized hibernate models and a second one which removed lazy initialized references


      Possible Solution:

      Before serializing the hiberante model we replace per reflection all accurences of lazy uninitialied objects with a null value. This could be done using an interceptor or bether within jboss framework at all to prevent the server from throwing classnotfoundexceptions.


      any comments welcome