Ok, that matches my assessment - we need a JPA-aware agent (what I
called fat agent).
BTW, this discussion happened to be very helpful in straightening
Cayenne PersistentUnitInfo ClassLoaders. We had our own version of
TemporaryClassLoader from the beginning, but is was used as the main
PersistentUnitInfo class loader, not the temp one (and provider
incorrectly called PersistentUnitInfo.getClassLoader() as a result).
I fixed it and got further down with OpenEJB JpaTest. Enhancer now
works. I'll see if I can address other errors.
You should ask David Blevins about his xbean-finder code which is
designed to detect such annotations.
I'll check it out.
Andrus
On Feb 22, 2007, at 8:45 PM, Dain Sundstrom wrote:
You can't really push a class back into the app. Instead you must
wait for the app to load (pull) a class and hook the load via the
javaagent.
In a managed (container) environment this works quite well because
the container can guarantee that the JPA provider is full
initialized before any app code is called. In an unmanaged
environment life is much more difficult since it is by definition
the application code that initializes the system. To get around
this, you will need the javaagent to search for persistence units
and determine which classes need to be enhanced. One nice thing,
is most people will use the @Entity annotation instead of XML to
declare their persistent beans, and this entity is easy to detect
directly using asm. You should ask David Blevins about his xbean-
finder code which is designed to detect such annotations.
-dain
On Feb 22, 2007, at 10:21 AM, Andrus Adamchik wrote:
I see how TemporaryClassLoader operates. We haven't been using
'getNewTempClassLoader' in the provider code as of yet. Let me
poke around and see if I am overcomplicating the issue... I still
don't understand how to push an enhanced class back into the app
classloader space, but maybe I am wrong (still thinking in Cayenne
classic terms), and this is not needed.
Andrus
On Feb 22, 2007, at 7:46 PM, Dain Sundstrom wrote:
Sorry, got busy and missed this email.
This is such a common problem, it was addressed directly by the
JPA specs. When loading classes for inspection use the class
loader returned from
javax.persistence.spi.PersistenceUnitInfo.getNewTempClassLoader().
For Cayenne's own PersistenceUnitInfo implementation, I suggest
you copy org.apache.openejb.core.TemporaryClassLoader which I
copied from OpenJPA and cleaned up.
-dain