IgorZ
IgorZ

Reputation: 1164

Tomcat H2 deployment

I have 2 situations.

hibernate.cfg:
<property name="connection.url">jdbc:log4jdbc:h2:./H2/test</property>
<property name="connection.driver_class">net.sf.log4jdbc.sql.jdbcapi.DriverSpy</property>
<property name="connection.username">user</property>
<property name="connection.password">password</property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
  1. H2 db is in my project near my src folder. If I try to test connection from simple class it works. It connects to the db that is in the right place in project folder.

  2. Now I'm making new configuration to launch tomcat + servlets. All is fine, but tomcat creates new H2 database in his folder: (apache-tomcat-8.0.17\bin\H2\test.mv.db). Is it possible to make tomcat to take (to use) my test.mv.db from my project's folder ?
    If I put my test.mv.db manualy from project into tomcat's dir - it is working (I'm not using "sa" with blank password). I don't want to place h2 db into user's folder like jdbc:h2:~/test).

Thank you.

Upvotes: 1

Views: 2896

Answers (1)

Vlad Mihalcea
Vlad Mihalcea

Reputation: 153780

  1. You should append the hibernate prefix to all your properties.

  2. Try giving H2 an absolute path to your database folder:

    <property name="hibernate.connection.url">jdbc:h2:file:/your-project-path/test-db</property>
    
  3. I don't think the Driver class setting is correct either. It should be:

    <property name="hibernate.connection.driver_class" value="org.h2.Driver" />
    

Upvotes: 1

Related Questions