I am not sure how exactly the classloader works right now but there should be one classloader per EntityManagerFactory and its lifecycle should be bound to the factory.
The jpa container defined in the OSGi spec should make sure to detect when a persistence unit bundle goes away and automatically unpublish the EntityManagerFactory and then close it. This will signal to all user bundles that use the factory that they should close down their EntityManagers. It uses a BundleListener or in fact a BundleTracker to do so. If you plan to rely on cooperating with a jpa container like aries then you should not need to implement a bundle listener yourself.
|