persistence@glassfish.java.net

A Question about code in EntityMangerSetupImpl

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Thu, 24 May 2007 18:16:19 -0700
Hi Tom, Gordon,

I have a question about following code from EntityMangerSetupImpl

    protected boolean updateServerPlatform(Map m, ClassLoader loader) {
        String serverPlatformClassName = PropertiesHandler.getPropertyValueLogDebug(TopLinkProperties.TARGET_SERVER, m, session);
               ....
               ....
        ServerPlatform serverPlatform = null;
        // New platform - create the new instance and set it.
--->A        Class cls = findClassForProperty(serverPlatformClassName, TopLinkProperties.TARGET_SERVER, loader);
        try {
            Class clz = oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.class;
--->B            Constructor constructor = cls.getConstructor(new Class[]{oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.class});
            serverPlatform = (ServerPlatform)constructor.newInstance(new Object[]{session});

Here depending on from which environment and from which method updateServerPlatform is called, the parameter loader is either the classloader that loads the application (PereistenceUnit) or the tempClassLoader which is expected to be a clone.

At point (A) above, we use the parameter 'loader' as the classloader to load the class specified by property TopLinkProperties.TARGET_SERVER. At point (B) we try to get constructor for cls with parameter 'oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.class'. If 'cls' is loaded by a different classloader than the classloader that loads 'DatabaseSessionImpl.class', the constructor will never be found. Infect, this is what is happening inside appclient for glassfish and we are not able to inject persistence artifacts into appclient.

The question is at point (A) above, why do we use the parameter 'loader' as the classloader to load the class specified by property TopLinkProperties.TARGET_SERVER?

Thanks,
Mitesh