openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "roger.keays" <>
Subject Re: Shared classloader and subclasses
Date Tue, 20 Mar 2007 07:48:12 GMT

I've been able to patch MetaDataRepository#getPCSubclasses() to work around
this problem (see below), but I'm a bit unsure about whether statics should
be used in PCRegistry or not. The listeners are stored in a static field,
which means they collect information about every application which loads
PCRegistry with the same class loader. Wouldn't the Broker object be a more
appropriate location for a PCRegistry without static fields?


Begin patch (from 0.9.6 source)

Index: src/main/java/org/apache/openjpa/meta/
--- src/main/java/org/apache/openjpa/meta/      
(revision 474176)
+++ src/main/java/org/apache/openjpa/meta/      
(working copy)
@@ -1243,7 +1243,16 @@
         Collection subs = (Collection) _subs.get(cls);
         if (subs == null)
             return Collections.EMPTY_LIST;
-        return subs;
+        /* only return subclasses we have metadata for */
+        Collection result = new LinkedList();
+        for (Iterator i = subs.iterator(); i.hasNext();) {
+            Class c = (Class);
+            if (_metas.containsKey(c) && _metas.get(c) != null) {
+                result.add(c);
+            }
+        }
+        return result;

roger.keays wrote:
> Hi there,
> I'm trying to move my openjpa libs from WEB-INF/lib to Tomcat's
> shared/lib, but it seems I have a border case which makes this difficult.
> The situation is that each instance of the webapp loads between 5 - 10
> subclasses of an abstract Entity. Which classes are loaded is specified by
> that instance's configuration file. This is done with some custom
> bootstrapping code which ignores the normal JPA persistence.xml
> mechanisms. Everything works fine when one instance is loaded, but when
> another is loaded with a different set of subclasses, things get a bit
> hairy.
> AFIACT, the problem is that the openjpa.enhance.PCRegistry class uses
> static fields to store Meta information. When the second instance is
> loaded, the PCRegistry has been initialized, but doesn't contain that
> instance's subclasses and an exception is thrown. This is not a problem
> using the WEB-INF/lib classloader of course because each instance has
> their own PCRegistry class.
> I'm wondering if anybody might be able to suggest a workaround. I'd be
> happy if there was a way to load all the subclass metadata into the
> PCRegistry, but I still need each instance of the webapp to only be aware
> of their own subclasses.
> Cheers,
> Roger

View this message in context:
Sent from the open-jpa-dev mailing list archive at

View raw message