How can I use derby in memory with jpa2?

simpatico picture simpatico · Nov 6, 2010 · Viewed 10.4k times · Source

Regardless of the following persistence.xml configuration the database is persisted on disk.

  <persistence-unit name="com.mysimpatico_inmemory_persistence_nbm_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.mysimpatico.memoplatform.persistence.entities.Expression</class>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:tempDb;create=true"/>
  <property name="javax.persistence.jdbc.password" value=""/>
  <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
  <property name="javax.persistence.jdbc.user" value=""/>
</properties>

http://wiki.apache.org/db-derby/InMemoryBackEndPrimer

Answer

Pascal Thivent picture Pascal Thivent · Nov 6, 2010

I'm using Derby in memory for testing and my configuration is very close to yours.

Here is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
  <persistence-unit name="TestPu" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.acme.Foo</class>
    <class>com.acme.Bar</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <!-- Common properties -->
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:test-jpa;create=true"/>
      <property name="javax.persistence.jdbc.user" value="APP"/>
      <property name="javax.persistence.jdbc.password" value="APP"/>

      <!-- EclipseLink specific properties -->
      <property name="eclipselink.target-database" value="Derby"/>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
      <property name="eclipselink.debug" value="ALL"/>
      <property name="eclipselink.weaving" value="static"/>
      <property name="eclipselink.logging.level" value="FINEST"/>
      <property name="eclipselink.logging.level.sql" value="FINEST"/>
      <property name="eclipselink.logging.level.cache" value="FINEST"/>
    </properties>
  </persistence-unit>
</persistence>

Where org.apache.derby:derby:jar:10.6.2.1 is on the classpath.

Now two questions/suggestions:

  • How do you know the database is persisted on disk?
  • If it really does, make sure you're using the persistence.xml you think you are.