Buggy code:
@ SuppressWarnings ( "serial" ) public abstract class AbstractBrokerFactory implements BrokerFactory { private static final Localizer _loc = Localizer . forPackage ( AbstractBrokerFactory . class ) ; private static final Map < Object , AbstractBrokerFactory > _pool = Collections . synchronizedMap ( new HashMap < Object , AbstractBrokerFactory > ( ) ) ; private final OpenJPAConfiguration _conf ; private transient boolean _readOnly = false ; private transient boolean _closed = false ; private transient RuntimeException _closedException = null ; private Map < Object , Object > _userObjects = null ; private final ReentrantLock _lock = new ReentrantLock ( ) ; private transient ConcurrentHashMap < Object , Collection < Broker > > _transactional = new ConcurrentHashMap < Object , Collection < Broker > > ( ) ; private transient Set < Broker > _brokers ; private transient Collection < String > _pcClassNames = null ; private transient Collection < ClassLoader > _pcClassLoaders = null ; private transient boolean _persistentTypesLoaded = false ; private transient Map < Object , Class < ? > [ ] > _lifecycleListeners = null ; private transient List _transactionListeners = null ; private Object _poolKey ; private Set < String > _supportedPropertyNames = new TreeSet < String > ( ) ; protected static Object toPoolKey ( Map map ) { } protected static void pool ( Object key , AbstractBrokerFactory factory ) { } public static AbstractBrokerFactory getPooledFactoryForKey ( Object key ) { } protected AbstractBrokerFactory ( OpenJPAConfiguration config ) { } public OpenJPAConfiguration getConfiguration ( ) { } public Broker newBroker ( ) { } public Broker newBroker ( String user , String pass ) { } public Broker newBroker ( boolean managed , int connRetainMode ) { } public Broker newBroker ( String user , String pass , boolean managed , int connRetainMode ) { } public Broker newBroker ( String user , String pass , boolean managed , int connRetainMode , boolean findExisting ) { } void initializeBroker ( boolean managed , int connRetainMode , BrokerImpl broker , boolean fromDeserialization ) { } protected void addListeners ( BrokerImpl broker ) { } private void loadPersistentTypes ( ClassLoader envLoader ) { } private boolean needsSub ( Class cls ) { } public void addLifecycleListener ( Object listener , Class [ ] classes ) { } public void removeLifecycleListener ( Object listener ) { } public void addTransactionListener ( Object listener ) { } public void removeTransactionListener ( Object listener ) { } public boolean isClosed ( ) { } public void close ( ) { lock ( ) ; try { assertOpen ( ) ; assertNoActiveTransaction ( ) ; synchronized ( AbstractBrokerFactory . _pool ) { if ( ( AbstractBrokerFactory . _pool . get ( _poolKey ) ) == ( this ) ) AbstractBrokerFactory . _pool . remove ( _poolKey ) ; } Broker broker ; for ( Iterator itr = _brokers . iterator ( ) ; itr . hasNext ( ) ; ) { broker = ( ( Broker ) ( itr . next ( ) ) ) ; if ( ( broker != null ) && ( ! ( broker . isClosed ( ) ) ) ) broker . close ( ) ; } if ( _conf . metaDataRepositoryAvailable ( ) ) { PCRegistry . removeRegisterClassListener ( _conf . getMetaDataRepositoryInstance ( ) ) ; } <START_BUG> Reflection . flushCaches ( _pcClassLoaders ) ; <END_BUG> _conf . close ( ) ; _closed = true ; Log log = _conf . getLog ( LOG_RUNTIME ) ; if ( log . isTraceEnabled ( ) ) _closedException = new IllegalStateException ( ) ; } finally { unlock ( ) ; } } public Properties getProperties ( ) { } public Map < String , String > getAllProperties ( ) { } public Set < String > getSupportedProperties ( ) { } public Object getUserObject ( Object key ) { } public Object putUserObject ( Object key , Object val ) { } public void lock ( ) { } public void unlock ( ) { } protected Object readResolve ( ) throws ObjectStreamException { } private Set newBrokerSet ( ) { } protected abstract StoreManager newStoreManager ( ) { } protected BrokerImpl findBroker ( String user , String pass , boolean managed ) { } protected BrokerImpl newBrokerImpl ( String user , String pass ) { } protected void setup ( ) { } protected BrokerImpl findTransactionalBroker ( String user , String pass ) { } protected void configureBroker ( BrokerImpl broker ) { } public void makeReadOnly ( ) { } protected Object getFactoryInitializationBanner ( ) { } private void assertOpen ( ) { } private void assertNoActiveTransaction ( ) { } boolean syncWithManagedTransaction ( BrokerImpl broker , boolean begin ) { } public Collection getOpenBrokers ( ) { } protected void releaseBroker ( BrokerImpl broker ) { } public Object getPoolKey ( ) { } void setPoolKey ( Object key ) { } private class RemoveTransactionSync implements Synchronization { private final Object _trans ; public RemoveTransactionSync ( Object trans ) { } public void beforeCompletion ( ) { } public void afterCompletion ( int status ) { } } private Collection getPcClassLoaders ( ) { } }

Fix:
Reflection . flushCaches ( ) ;