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 ?

2
  • I am not sure , but seems like you are using HSQLDB in memory way. It's not the <property name="hibernate.hbm2ddl.auto" value="create"/>. Commented Nov 13, 2014 at 15:39
  • As you can see in config I am using disk space db. Commented Nov 13, 2014 at 20:29

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.