Etam
Etam

Reputation: 4673

Persistence unit is not persistent

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.

Upvotes: 2

Views: 312

Answers (1)

Pascal Thivent
Pascal Thivent

Reputation: 570285

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.

Upvotes: 3

Related Questions