Question

I am using Spring MVC 3.2 Embedded database (H2) Support for storing real-time progress of tasks,queuing notifications and some temporary logs.The only problem with this approch is that my data gets vanished ; If the application redeploys or server restarts.This scenario is probably very rare in production environment but still I want to know that using embedded databases in production environment is a good choice or not?..Or is there any way to persist embedded database state to hard-disk so that the next time server boots we can restore the database state to stored checkpoint?

Thank you.

No correct solution

OTHER TIPS

Embedded databases are not meant for use in a Production Environment. They are meant for a quicker development option as you do not need to have the dependency of an external database running. With an embedded database, you can programmatically fire it up and optionally initialize it based on your needs.

The reason your changes are being lost during redeployments is because you are using the in-memory version of HsQL instead of In-process(Standalone file) mode. You can use the Standalone mode which keeps the changes persistent.

In-Process (Standalone) Mode

This mode runs the database engine as part of your application program in the same Java Virtual Machine. For most applications this mode can be faster, as the data is not converted and sent over the network. The main drawback is that it is not possible by default to connect to the database from outside your application. As a result you cannot check the contents of the database with external tools such as Database Manager while your application is running. In 1.8.0, you can run a server instance in a thread from the same virtual machine as your application and provide external access to your in-process database.

The recommended way of using the in-process mode in an application is to use an HSQLDB Server instance for the database while developing the application and then switch to In-Process mode for deployment.

An In-Process Mode database is started from JDBC, with the database file path specified in the connection URL. For example, if the database name is testdb and its files are located in the same directory as where the command to run your application was issued, the following code is used for the connection:

    Connection c = DriverManager.getConnection("jdbc:hsqldb:file:testdb", "sa", "");
The database file path format can be specified using forward slashes in Windows hosts as well as Linux hosts. So relative paths or paths that refer to the same directory on the same drive can be identical. For example if your database path in Linux is /opt/db/testdb and you create an identical directory structure on the C: drive of a Windows host, you can use the same URL in both Windows and Linux:

    Connection c = DriverManager.getConnection("jdbc:hsqldb:file:/opt/db/testdb", "sa", "");
When using relative paths, these paths will be taken relative to the directory in which the shell command to start the Java Virtual Machine was executed. Refer to Javadoc for jdbcConnection for more details.

HSQL documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top