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>
8
  • Do you want hibernate to populate the database upon startup? Commented May 19, 2014 at 6: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? Commented May 19, 2014 at 6: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. Commented May 19, 2014 at 6: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. Commented May 19, 2014 at 6:43
  • You could probably initialize user db with data you need by means of liquibase or similar means. See this question: stackoverflow.com/questions/10620131/… for example Commented May 19, 2014 at 8:31

1 Answer 1

0

The embedded database is not meant to work on different computers, it's a local database and not shared, the only way to achieve sharing this database is by using a remote version database like MySQL (which works on a server) instead of an embedded one, fortunately, H2 database has a remote version, it can be embedded, remote, or in-memory database. So change this

<property name="hibernate.connection.url">jdbc:h2:~/test</property>

to this

<property name="hibernate.connection.url">jdbc:h2:tcp://localhost:9092/test</property>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.