Exception when deploying Entities with @Reference(lazy=true) to app server

102 views
Skip to first unread message

Ellen Kraffmiller

unread,
Nov 10, 2013, 12:59:04 PM11/10/13
to mor...@googlegroups.com
Hi,

I have an application that works with a deeply nested tree of objects, that I'm representing as Morphia Entities.  In order to prevent too much data being loaded from the database, I'm using @Reference with lazy loading.  I have code which works fine in a unit test, but when I deploy to my app server (Glassfish), I get an Exception that seems to indicate I'm missing a library that is needed at runtime, in order to implement the lazy loading.  Is this a known issue? Do I have to update my Glassfish installation with the cglib jar files, or is there a way to manage this my project configuration?
 I've read other posts that suggest to use lists of ObjectIds, rather than @Reference to represent object relationships.  I like being able to traverse the tree with object references, but if ObjectIds are a better solution, I can switch to that.

Thanks,
Ellen

Here is the exception:

net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:304)
    at com.thoughtworks.proxy.factory.CglibProxyFactory.createWithConstructor(CglibProxyFactory.java:150)
    at com.thoughtworks.proxy.factory.CglibProxyFactory.createProxy(CglibProxyFactory.java:105)
    at com.thoughtworks.proxy.toys.hotswap.HotSwappingInvoker.proxy(HotSwappingInvoker.java:153)
    at org.mongodb.morphia.mapping.lazy.CGLibLazyProxyFactory.createListProxy(CGLibLazyProxyFactory.java:47)
    at org.mongodb.morphia.mapping.ReferenceMapper.readCollection(ReferenceMapper.java:206)
    at org.mongodb.morphia.mapping.ReferenceMapper.fromDBObject(ReferenceMapper.java:163)
    at org.mongodb.morphia.mapping.Mapper.readMappedField(Mapper.java:598)
    at org.mongodb.morphia.mapping.Mapper.fromDb(Mapper.java:580)
    at org.mongodb.morphia.mapping.Mapper.fromDBObject(Mapper.java:296)
    at org.mongodb.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:78)
    at org.mongodb.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:65)
    at org.mongodb.morphia.query.MorphiaIterator.next(MorphiaIterator.java:60)
    at org.mongodb.morphia.query.QueryImpl.get(QueryImpl.java:399)
    at edu.harvard.iq.text.model.NodeHierarchy.getRootNodes(NodeHierarchy.java:174)
    at edu.harvard.iq.text.GetClusteringServlet.processRequest(GetClusteringServlet.java:72)
    at edu.harvard.iq.text.GetClusteringServlet.doGet(GetClusteringServlet.java:179)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
    ... 47 more
Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/proxy/toys/hotswap/Swappable
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    ... 52 more
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.proxy.toys.hotswap.Swappable not found by org.glassfish.hk2.external.cglib [22]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 54 more

Ellen Kraffmiller

unread,
Nov 10, 2013, 1:01:04 PM11/10/13
to mor...@googlegroups.com
Just to clarify, the exception doesn't happen when I deploy, but when I run the deployed code from within a servlet

Justin Lee

unread,
Nov 10, 2013, 1:07:28 PM11/10/13
to mor...@googlegroups.com
you need to include this in your pom:

<dependency>
            <groupId>com.thoughtworks.proxytoys</groupId>
            <artifactId>proxytoys</artifactId>
            <version>1.0</version>
</dependency>


--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ellen Kraffmiller

unread,
Nov 10, 2013, 1:26:17 PM11/10/13
to mor...@googlegroups.com
Hi Justin,
Thanks for the quick response. I added that dependency, and checked to make sure that I have proxytoys-1.0.jar in my war file, but still getting the same Exception & stack trace.
-Ellen


--
You received this message because you are subscribed to a topic in the Google Groups "Morphia" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/morphia/pDalUe7Y7w8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to morphia+u...@googlegroups.com.

Justin Lee

unread,
Nov 10, 2013, 6:53:03 PM11/10/13
to mor...@googlegroups.com
OK.  Seeing the felix bits in the stacktrace makes me wonder if you're running afoul of the missing OSGi support.  Morphia works fine in a standard war but osgi support is still pending:  https://github.com/mongodb/morphia/search?q=osgi&ref=cmdform&type=Issues

Ellen Kraffmiller

unread,
Nov 11, 2013, 10:37:24 AM11/11/13
to mor...@googlegroups.com
Ok, thanks.  Is there a workaround until this issue is fixed?  I'm looking at the Glassfish documentation, but I don't think it's possible to deploy a war file outside of the OSGi context.
Reply all
Reply to author
Forward
0 new messages