HSQL DB in Servlet: lock file not released
===

I am running a HSQLDB inside a Servlet. When I redeploy the application to the web server the .lck file is not properly released and the HSQL server cannot load the file.

Web server is Tomcat 7.0.22 shipped with NetBeans...

Any ideas why this is happening?

Here is the init code:

    @Override public void init() throws ServletException {
            HsqlProperties p = new HsqlProperties();
            p.setProperty("server.database.0", dbPath);
            p.setProperty("server.dbname.0", Environment.PERSISTENCE_HSQL_DB_NAME);
            p.setProperty("server.port", Environment.PERSISTENCE_HSQL_PORT);
            server = new Server();
            server.setProperties(p);
            server.setSilent(false);
            server.setTrace(true);
            server.setLogWriter(new PrintWriter(System.out));
            server.setErrWriter(null);
            server.start();

            server.checkRunning(true);
            
            /* Exception handling */
        }

Here is my shutdown / destroy method:

    @Override
    public void destroy() {
        super.destroy();
        server.setNoSystemExit(true);
        server.stop();
        server.shutdown();
        controller.shutdown();
    }

I am using JPA. If the database loads (first start) the app is working fine. Here is my persistence.xml:

    <persistence-unit name="embedded_hsql" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <!-- Entities -->
        <properties>
            <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
            <property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost:9001/fst_db;hsqldb.lock_file=false"/>
            <property name="hibernate.connection.username" value="SA"/>
            <property name="hibernate.connection.password" value=""/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.connection.SetBigStringTryClob" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="current_session_context_class" value="thread" />
            <property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
        </properties>
    </persistence-unit>   

I added "hsqldb.lock_file=false" for testing purposes which has no effect at all. In general I don't want to disable file locking...

Thanks!

