I'm not sure if this is a limitation of the JVM; there may be no solution if
that is the case.
For a simple test case, consider any non-EE servlet container (like Tomcat,
Resin, etc) attempting to run with dynamic weaving by adding -javaagent to the
JVM classpath. The agent starts up in the system classloader, but the classes
that need to be woven are loaded by classloaders specified by the container.
Thus, the first time any web application running in the J2SE container
references an @Entity class, a ClassNotFound exception is thrown.
One probable workaround would be to use static weaving. Alternatively, one
could also switch to using a full-blown J2EE container, but this isn't always
It would be nice if the agent could determine which classloader was asking for
the class in question and fetch it from/for that classloader. I don't
understand the gory details of JVM class loading well enough to know whether
this is practical or even possible, however.