tags:

views:

34

answers:

1

I need persistence unit that creates embedded database which stays persistent after closing EntityManager.

This is my PU:

<persistence-unit name="hello-jpa" transaction-type="RESOURCE_LOCAL">
  <class>hello.jpa.User</class>
  <properties>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.format_sql" value="true"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
    <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
    <property name="hibernate.connection.username" value="sa"/>
    <property name="hibernate.connection.password" value=""/>
    <property name="hibernate.connection.url" value="jdbc:hsqldb:target/hsql.db"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
  </properties>
</persistence-unit>

And it deletes data after closing application.

+1  A: 

My understanding of the documentation is that the "old" URL jdbc:hsqldb:. creates or connects to the same database as the new form for the URL jdbc:hsqldb:mem:. (i.e. in memory).

So try with the following URL instead: jdbc:hsqldb:file:target/hsql.db.

Pascal Thivent
I doesn't work either :(. There is no such file lie target/hsql.db in both cases...
etam
@etam Could you try with an absolute path (just to check)? I have a doubt about the working directory.
Pascal Thivent
All I have is (with relative and absolute):~/etam-svn/code/java/hello-jpa > ls target/classes hsql.db.log maven-archiverhello-jpa-derby-1.0-SNAPSHOT.jar hsql.db.properties test-classes
etam
@etam I just did a test on my side and the following url `jdbc:hsqldb:file:target/testdb` definitely worked: ls target/classes test-classes testdb.properties xsdsurefire-reports testdb.log testdb.script
Pascal Thivent
Does it persist objects between sessions?
etam