javassist class loading in OSGi environment

730 views
Skip to first unread message

Gabriel Vince

unread,
May 4, 2012, 9:36:56 AM5/4/12
to orient-...@googlegroups.com
Hello,

I see a new way of handling object database was added, using build 5481, good work :)
but there's a little problem in OSGi to load classes when trying to serialize the saved object.. Even setting the class loader did not help :(

the bundle contains all refered classes, OrientDB client libraries and javassist library as well

Anybody with an idea?

Gabriel

code:
There are simple POJO Entity object Dimension referencing a list of categories

        ClassLoader originalClassLoader = null;
       
        try {
            String uri = this.getDatabaseUri(database);
            db = this.getDatabase(uri, LOGIN, PASSWORD);// aquire from pool
            db.setSaveOnlyDirty(true);
            originalClassLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(javassist.util.proxy.ProxyObject.class.getClassLoader());
            db.begin();

            for (Category c : dimension.getCategories()) {
                // seems this back reference creates problems (loops) fetching
                // an object :(
                c.setDimension(dimension);

// .. deleted.. setting property values
                db.save(c);
            }

            db.save(dimension);

            db.commit();
        } catch (Exception ex) {
            logger.log(Level.SEVERE, "defineDimension", ex);
            if (db != null) {
                db.rollback();
            }
            exx = ex;
        } finally {
           
            if(originalClassLoader!=null)
                Thread.currentThread().setContextClassLoader(originalClassLoader);
           
            if (db != null) {
                db.close();
            }
        }


Caused by: java.lang.RuntimeException: by java.lang.NoClassDefFoundError: javassist/util/proxy/ProxyObject
    at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:514)[909:com.apogado.ste.datastore:0.1.0]
    at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:491)[909:com.apogado.ste.datastore:0.1.0]
    at javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.java:427)[909:com.apogado.ste.datastore:0.1.0]
    at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:399)[909:com.apogado.ste.datastore:0.1.0]
    at com.orientechnologies.orient.object.enhancement.OObjectEntityEnhancer.getProxiedInstance(OObjectEntityEnhancer.java:104)[909:com.apogado.ste.datastore:0.1.0]
    at com.orientechnologies.orient.object.db.OObjectDatabaseTx.newInstance(OObjectDatabaseTx.java:111)[909:com.apogado.ste.datastore:0.1.0]
    ... 56 more
Caused by: javassist.CannotCompileException: by java.lang.NoClassDefFoundError: javassist/util/proxy/ProxyObject
    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:170)[909:com.apogado.ste.datastore:0.1.0]
    at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:506)[909:com.apogado.ste.datastore:0.1.0]
    ... 61 more
Caused by: java.lang.NoClassDefFoundError: javassist/util/proxy/ProxyObject
    at java.lang.ClassLoader.defineClass1(Native Method)[:1.6.0_29]
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)[:1.6.0_29]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)[:1.6.0_29]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_29]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_29]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_29]
    at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_29]
    at javassist.util.proxy.FactoryHelper.toClass2(FactoryHelper.java:182)[909:com.apogado.ste.datastore:0.1.0]
    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:164)[909:com.apogado.ste.datastore:0.1.0]
    ... 62 more
Caused by: java.lang.ClassNotFoundException: javassist.util.proxy.ProxyObject
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)[osgi-3.6.2.R36x_v20110210.jar:]
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)[osgi-3.6.2.R36x_v20110210.jar:]
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)[osgi-3.6.2.R36x_v20110210.jar:]
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)[osgi-3.6.2.R36x_v20110210.jar:]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_29]
    ... 71 more

Luca Molino

unread,
May 4, 2012, 12:31:57 PM5/4/12
to orient-...@googlegroups.com
That is a bit strange, it seems the classloader finds javassist library but not all its classes. Can you try setting the classloader before opening the database instance?

2012/5/4 Gabriel Vince <gabrie...@apogado.com>

Luca Garulli

unread,
May 13, 2012, 7:00:28 PM5/13/12
to orient-...@googlegroups.com
Hi,
this has been fixed by Roberto Franchini as SVN r5575: the classloader management now is internal in OrientDB and the user hasn't to handle manually anymore.

Lvc@

Gabriel Vince

unread,
May 14, 2012, 7:23:57 AM5/14/12
to orient-...@googlegroups.com
Great! Thankx ..

Carpe diem
            Gabriel
Reply all
Reply to author
Forward
0 new messages