HSQL DB in Servlet: Lock file not released

I am running HSQLDB inside a servlet. When I redistribute the application to the web server, the .lck file will not be correctly released and the HSQL server will not be able to upload the file.

The Tomcat 7.0.22 web server comes with NetBeans ...

Any ideas why this is happening?

Here is the initialization 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 is loading (first start), the application works 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. In general, I do not want to disable file locking ...

Thank!

+5
source share
3 answers

-, :

hsqldb start/stop.

+1

, :

@Override
public void destroy() {
    controller.shutdown();
    PersistenceUtility.getInstance().closeAllEntityManagers();

    try {
        EntityManager em = PersistenceUtility.getInstance().createEntityManager();
        em.getTransaction().begin();
        Query shutdownQuery = em.createNativeQuery("SHUTDOWN");
        shutdownQuery.executeUpdate();
        em.getTransaction().commit();
    } catch (Throwable t) {
        Environment.LOGGER.debug("Database connection closed");
    }

    server.signalCloseAllServerConnections();
    server.shutdown();
    super.destroy();
}

, SHUTDOWN , , EntityManager. , ​​ , EntityManager ...

Throwable t, :

javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not execute native bulk manipulation query
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
    at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:58)
    at com.convista.fst.manager.ConfigurationServlet.destroy(ConfigurationServlet.java:115)
    at org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1417)
    at org.apache.catalina.core.StandardWrapper.stopInternal(StandardWrapper.java:1764)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:230)
    at org.apache.catalina.core.StandardContext$4.run(StandardContext.java:5449)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.hibernate.exception.JDBCConnectionException: could not execute native bulk manipulation query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:174)
    at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1163)
    at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:334)
    at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:49)
    ... 6 more
Caused by: java.sql.SQLTransientConnectionException: connection exception: connection failure: java.net.SocketException: Software caused connection abort: socket write error
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.close(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:534)
    at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:269)
    at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:169)
    ... 9 more
Caused by: org.hsqldb.HsqlException: connection exception: connection failure: java.net.SocketException: Software caused connection abort: socket write error
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.ClientConnection.execute(Unknown Source)
    ... 13 more

, ?

0

HSQLDB 2.4.1, , HSQL - shutdownCatalogs shutdownWithCatalogs org.hsqldb.server.Server.

:

server.shutdownCatalogs(org.hsqldb.Database.CLOSEMODE_NORMAL);

One obvious problem with this is that stop () is ultimately called when the last database is closed, and then shutdown () is called, which leads to some redundant internal calls, but that doesn't seem harmful.

0
source

All Articles