2

Hello I am creating a desktop application using Javafx ,embedded h2 database and hibernate for making connection between them. My application running well in my desktop but while i am running the executable jar file on other system it unable to fetch data from data base that means my db file is not embedded in application jar file. my database file resides in root directory .kindly tell me how can i put embedded h2 database file into that executable jar file or what change should i make in hibernate.cfg to put my test.h2.db file in app.jar.

My hibernate.cfg file is 
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">org.h2.Driver</property>
    <property name="hibernate.connection.url">jdbc:h2:~/test</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.connection.password"/>
    <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
    <property name="current_session_context_class">thread</property>
    <property name="cache.provider_class">
            org.hibernate.cache.NoCacheProvider
        </property>
    <property name="hbm2ddl.auto">update</property>
    <property name="show_sql">true</property>
    <mapping class="model.Employee"/>
  </session-factory>
</hibernate-configuration>
Shardendu
  • 3,480
  • 5
  • 20
  • 28
  • Do you want hibernate to populate the database upon startup? – Alexandre Santos May 19 '14 at 06:11
  • IMHO, in Embedded mode, the database will be created in relative to the user home directory. The db file cannot be placed inside the jar file. Just think about it, why do you want to put something in your jar, which is going to be modified by the program? – Hirak May 19 '14 at 06:32
  • thnkx for reply...No, i want to populate when i click on retrieve action. actually data is getting populated properly but the h2 database file is present on my desktop root directory. I want to know how can i embed that test.h2.db file inside that application jar so i can run it on other system as well. – Shardendu May 19 '14 at 06:36
  • hello Hirak, If i cannot put my db file inside jar so is there any way that i can make my database portable means i want to distribute my app to different user to run separately .so when user run the application(executable jar) it creates its own db on its system. – Shardendu May 19 '14 at 06:43
  • You could probably initialize user db with data you need by means of liquibase or similar means. See this question: http://stackoverflow.com/questions/10620131/running-liquibase-within-java-code for example – skegg99 May 19 '14 at 08:31
  • As documented, you could [convert the database to a read-only database in a zip or jar file](http://h2database.com/html/features.html#database_in_zip). But I'm not sure if this is really what you want. – Thomas Mueller May 19 '14 at 09:11
  • in read-only database we can't update,insert the records so i don't want this. actually i want to distribute my javafx application to many user so the can run this application with individual database – Shardendu May 19 '14 at 10:48
  • Hey Harik You are right that database will be created relative to the user home directory but it is not getting created on other user directory .Is there any permission i need to provide so it can get created in any system – Shardendu May 20 '14 at 06:00

0 Answers0