I am using HSQLDB with Hibernate 5 and Spring 4.
I have some beans definitions in my spring-context.xml:
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath*:database/database_schema.sql"/>
</jdbc:embedded-database>
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="configLocation" value="hibernate/hibernate.cfg.xml"/>
<beans:property name="annotatedClasses">
<beans:list>
...lot of project beans path values..
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory"/>
</beans:bean>
And Hibernate.cfg.xml contains:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.enable_lazy_load_no_trans">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:file:D/database</property>
<property name="connection.pool_size">10</property>
<property name="connection.username">SA</property>
<property name="connection.password"></property>
</session-factory>
</hibernate-configuration>
All dao and services layers is working fine. Data is always saved and all is all right.
But in the next launch all data is deleting from database.
I am trying to save my database data in file and to use this data again, and I have tried many variants. The last of them is from question about HSQLDB url config
I have added the line to my hibernate.cfg.xml file:
<property name="connection.url">jdbc:hsqldb:file:D/database</property>
It doesn't helped to me. There is no file creating in this path.
Also i am trying to use the advice from question and to use SCRIPT SQL command, but I do not fully understand how to properly use it and where i must to place it directly?
Question: How should I configure HSQLDB to save all data from my database to a file after closing app and to re-use this data after opening this application again? Can you write some small and valid example with the correct configuration of HSQLDB for this question?
Edit #1: Thank's jchampemont, i tried your variant and all your steps, but still nothing. The file is still doesn't exists :( Hibernate file is picked, all hibernate config is working fine.
Issue is fixed! Thank's to jchampemont and to fredt
I have forgot to delete this values in hibernate.cfg.xml...:
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:file:D:/database.lck</property>
<property name="connection.pool_size">10</property>
<property name="connection.username">SA</property>
<property name="connection.password"></property>
And i have created the bean dataSource like in jchampemont answer After deleting this 4 lines - everything start's to work fine, base were created in D:\database folder and everything is cool. Thank's for answers! Peace :)