0

I am using H2 as my dev database for an application I am writing. The app is deployed with Jetty and the connection is handled through Hibernate. To construct the tables, I am using the INIT parameter in the connection URL to run statements.

The problem is that it seems like this connection resets frequently, re-running that script (and thus erasing everything that has been stored in the database since last startup). This seems to happen almost immediately after startup.

At the end of my script, I have added the following which allows me to confirm that this script is run after the initial startup of the application:

DROP TABLE IF EXISTS system_msg;
CREATE TABLE system_msg (
    id int AUTO_INCREMENT NOT NULL,
    msg_date timestamp NULL,
    msg text NULL,
    PRIMARY KEY(id)
);
INSERT INTO system_msg(msg_date, msg)
VALUES (NOW(), 'Database schema created from DDL script');

On application startup, I am populating the application with some core data, using Hibernate. A webpage menu-structure is one of the entities that is generated on startup, and typically I can only load the page once. The second time I load the page, I get something like this:

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.example.web.model.front.Menu#1]

This indicates that the cached entity was not found in the database anympore. If I look at the H2 database using the web console, I can indeed see that the init script has been run again (looking at the timestamp for the post in the system_msg table)

I am using Ehcache as well as 2nd level cache, but I am not sure if this is relevant to the problem. In case it is, here is the current configuration file: http://pastebin.com/nGG3eENf

I am developing in Eclipse (Indigo), using Maven (embedded). I thought at first that it reset the H2 database server whenever I did code changes that triggered a behind-the-scenes reset of the Jetty instance, but it also happens without touching the code.

Other specifications:

  • Windows 7
  • H2 v1.3.168
  • Hibernate (and Ehcache) v4.1.7.Final
  • Jetty Maven plugin (if relevant?) v8.1.3.v20120416

Are there any settings I have missed, or any other possible explanation to why my H2 database keeps resetting?

4

0 回答 0