Christian,
  Thanks this lead me to the solution.

  The issue was not classloader but an import issue. An RCP application has a 
"target platform" that is dynamically searched. When I explicitly added the 
apache bundles to the bundle, the Class.forName found the class and the 
database is shutting down properly. 

  Lesson learned: check the simple stuff before assuming it is hard!

Tim

-----Original Message-----
From: Christian Schneider [mailto:cschneider...@gmail.com] On Behalf Of 
Christian Schneider
Sent: Monday, January 2, 2017 09:39
To: Derby Discussion <derby-user@db.apache.org>
Subject: Re: Shutdown Derby database using JPA not DriverManager

You can try to set the thread context classloader to the classloader of your 
bundle and make sure your bundle imports the derby classes.

Christian

On 02.01.2017 15:33, Timothy Vogel wrote:
> Christian,
>    Good to hear from you again.  Hope all is well!
>
>    The "OSGI application" is an Eclipse RCP client, not a server side 
> implementation.  I'm using RESOUCE_LOCAL as recommended with an SE 
> application.  Derby is used in embedded mode within the same JVM as the 
> client.
>
>    I am hoping there is either an undocumented capability within Derby or a 
> way to get the DriverManager class from JPA provider (EclipseLink).  Failing 
> those options, I will have to stop / restart the client multiple times.
>
> Tim
>
> -----Original Message-----
> From: Christian Schneider [mailto:cschneider...@gmail.com] On Behalf 
> Of Christian Schneider
> Sent: Monday, January 2, 2017 07:32
> To: Derby Discussion <derby-user@db.apache.org>
> Subject: Re: Shutdown Derby database using JPA not DriverManager
>
> You should avoid using Persistence.createEntityManagerFactory. It does not 
> work well in OSGi. Instead use Aries JPA or Aries transaction control.
> Both can provide you with a fully configured EntityManagerFactory and 
> EntityManager that copes well with the dynamics of OSGi.
>
> Christian
>
> On 02.01.2017 12:52, Timothy Vogel wrote:
>> 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?
>>
>
> --
> Christian Schneider
> http://www.liquid-reality.de
>
> Open Source Architect
> http://www.talend.com
>


--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

Reply via email to