I have an OSGI application that uses Derby for persistence and Eclipse Link as 
a JPA provider.  I leave starting the Derby instance to JPA and 
persistence.xml.  

    factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, 
props);

Persistence.xml
    <properties>
                <property name="eclipse.weaving" value="false" />
                <property name="javax.persistence.jdbc.driver" 
value="org.apache.derby.jdbc.EmbeddedDriver" />
                <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:pathToDb" />
                <property name="eclipselink.logging.level.sql" value="FINEST" />
                <property name="eclipselink.logging.parameters" value="true" />
        </properties>


At one point in the application, I need to stop the underlying Derby database. 
All of the examples show calling:
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); 
    DriverManager.getConnection("jdbc:derby:pathToDb;shutdown=true");   

This is problematic, especially in an OSGI application with multiple class 
loaders. I have tried using 
    if (factory.isOpen())
                        factory.close();
but this does not shutdown the Derby instance, only the JPA connection to it.

I tried using the OSGI console to stop the persistence related bundles 
including javax.persistence, JPA and Derby.  Stopping these did not release the 
file locks that Derby put on log files.

Is there a way, using JPA, to shutdown the underlying Derby instance?

Reply via email to