1

I am using JavaSE + JPA + Hibernate + HSQLDB.

My persistence xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="persistence" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>sk.tokra.jpa.model.TestDB</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:C:\Dev\db\hsqldb_db" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="false" />
            <property name="hibernate.hbm2ddl.auto" value="create"/>
        </properties>
</persistence-unit>
</persistence>

I create table, put object there, findObject by id returns my obj [ok], I stop app - Next start app with read, gets me null object, when I find by id (table is empty).

I thought that:

<property name="hibernate.hbm2ddl.auto" value="create"/>

wont drop my table,

Any ideas ?

To Kra
  • 3,344
  • 3
  • 38
  • 45

2 Answers2

6

As explained in this answer, the value create will create the schema, destroying previous data. Try with update instead if you want to preserve data.

Community
  • 1
  • 1
David Levesque
  • 22,181
  • 8
  • 67
  • 82
2

"create" does not DROP your table, it creates the schema and deletes your data.

bradleyfitz
  • 686
  • 4
  • 8