After a month working on a java Desktop application with embded HSQLDB (with hibernate), whene i package it to a jar file, HSQLDB seems to have no data in it at all.
I checked that ismdb.script exists in the jar and that it contains the data.
Here's the structure (HSQLDB data is in the DATA folder)
MyProjet
|___Main.java
|___resources
|____DATA
and here's my hibernate.cfg.xml
<?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="connection.url">jdbc:hsqldb:res:./data/ismdb</property>
<property name="connection.driver_class">org.hsqldb.jdbc.JDBCDriver</property>
<property name="hibernate.search.default.directory_provider">filesystem</property>
<property name="hibernate.search.default.indexBase">./data/</property>
<property name="hbm2ddl.auto">update</property>
<property name="connection.username">root</property>
<property name="connection.password">psw</property>
<mapping class="com.storeengine.model.Categories"/>
<mapping class="com.storeengine.model.Product"/>
<mapping class="com.storeengine.model.Row"/>
<mapping class="com.storeengine.model.Store"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
When i try a SELECT on a table i get java.lang.NullPointerException.
I tried all kind of paths, the only case where it works is when i set the database path to the project actual DATA folder, but of course i can't ship the software with source code. I need to have a single JAR with everything included in it.
Please help, i'm really stuck. thanks
So i found the solution. It seems from what i learned impossible to have hsqldb embdded 100% in the same jar. You will need to place the data folder outside the project.
In my case i found out that hsqldb (or hibernate) was creating empty folder with the path i spicified (./data/ismdb) in the machine root folder, all i had to do is to copy the content of data folder from my project to the created folder and voilà.