Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use derby in memory with jpa2?

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

like image 446
simpatico Avatar asked Nov 06 '10 22:11

simpatico


People also ask

Is Apache Derby an in memory database?

For testing and developing applications, or for processing transient or reproducible data, you can use Derby's in-memory database facility. An in-memory database resides completely in main memory, not in the file system.


1 Answers

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.
like image 125
Pascal Thivent Avatar answered Dec 16 '22 21:12

Pascal Thivent