6 Replies Latest reply on Mar 15, 2010 3:21 PM by dgolovin

    Hibernate tools keeps lock on HSQLDB

    coenos

      Hi,

       

      I have HSQLDB 1.8.1.2 installed and I am trying to create a Hibernate configuration. I have done this several times already for Oracle, Derby and now HSQLDB. However, with HSQLDB I keep getting the following Exception when refreshing the Hibernate config:

       

      java.sql.SQLException: The database is already in use by another process: org.hsqldb.persist.NIOLockFile@7a80f893[file =C:\Apps\hsqldb_1_8_1_2\hsqldb\data\seamdemoDB.lck, exists=true, locked=false, valid=false, fl =null]: java.lang.Exception: checkHeartbeat(): lock file [C:\Apps\hsqldb_1_8_1_2\hsqldb\data\seamdemoDB.lck] is presumably locked by another process

       

      I searched the web and apparently Eclipse is keeping the seamdemoDB.lck alive. When I close Eclipse the lock file dissappears. I know I am able to change all to a MEM db but I do not want this.

       

      Today I upgraded Eclipse to use the latest JBoss tools and after a clean install, it worked once, then after an Eclipse restart, it failed again.

       

      Does anyone have a solution for this or do I need to raise a JIRA issue?

       

      Thanks!

       

      Coenos

        • 1. Re: Hibernate tools keeps lock on HSQLDB
          maxandersen

          Does right clicking on the Hibernate Configuration and click Close help ?

           

          The configuration should though not have *any* locks on the database unless you actually used the database - what steps did you do before the lock is there ?

           

          Another culprit can be the DTP connection which you might have asked to connect on startup and then it would be holding a lock too.

          • 2. Re: Hibernate tools keeps lock on HSQLDB
            coenos

            Hi Max,

             

            thanks for your reply.

             

            Closing the connection does not release the lock. The problem occurs when I open the Hibernate Configuration, see picture. However, when I click on the database (+) to open and see which entities there are, I get the Exception. This is when I actually use the database.

             

            openconfig.JPG

             

            org.hibernate.exception.JDBCConnectionException: Getting database metadata
                at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97)
                at org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect.getMetaData(AbstractMetaDataDialect.java:64)
                at org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect.caseForSearch(AbstractMetaDataDialect.java:163)
                at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getTables(JDBCMetaDataDialect.java:22)
                at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:476)
                at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:74)
                at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:116)
                at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
                at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:107)
                at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:63)
                at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
                at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:234)
                at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
            Caused by: java.sql.SQLException: The database is already in use by another process: org.hsqldb.persist.NIOLockFile@7a80f893[file =C:\Apps\hsqldb_1_8_1_2\hsqldb\data\seamdemoDB.lck, exists=true, locked=false, valid=false, fl =null]: java.lang.Exception: checkHeartbeat(): lock file [C:\Apps\hsqldb_1_8_1_2\hsqldb\data\seamdemoDB.lck] is presumably locked by another process.
                at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
                at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
                at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
                at org.hsqldb.jdbcDriver.connect(Unknown Source)
                at org.hibernate.console.FakeDelegatingDriver.connect(FakeDelegatingDriver.java:40)
                at java.sql.DriverManager.getConnection(DriverManager.java:582)
                at java.sql.DriverManager.getConnection(DriverManager.java:154)
                at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
                at org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect.getConnection(AbstractMetaDataDialect.java:122)
                at org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect.getMetaData(AbstractMetaDataDialect.java:61)
                ... 11 more

             

            The lock is never released, even after closing or refreshing the configuration. The lock is only released after closing Eclipse. But even then the lck file is not removed, I need to remove it myself.

             

            I am not using DTP, only JBoss tools (Hibernate tools, Seam tools explicitly).

             

            I think Hibernate Tools is somehow not closing the connection to the DB after refreshing the Hibernate configuration, what do you think?

             


            Thanks,

            Coen

            • 3. Re: Hibernate tools keeps lock on HSQLDB
              coenos

              Ok, just after posting my reply I saw that I can seta property to prevent the lock file from even being created.

               

              hsqldb.lock_file=false

               

              This fixes the problem also

               

              Cheers,

              Coenos

              • 4. Re: Hibernate tools keeps lock on HSQLDB
                dgolovin
                Another solution is starting HSQL in server mode like it is explained in this article How to Use HSQL Database With JBossTools Right Way.
                • 5. Re: Hibernate tools keeps lock on HSQLDB
                  coenos

                  Hi Denis,

                   

                  yes I saw that article, but my development environment is set up differently, I don't use DTP for instance.

                   

                  And I had all of that stuff working with Oracle XE and Derby. Only with HSQLDB I had this locking issue.

                   

                  Cheers,

                  Coenos

                  • 6. Re: Hibernate tools keeps lock on HSQLDB
                    dgolovin

                    Your solution is good and simple I'll mention this in article for in process option.

                     

                    I thought you can skip all environment settings explained in article and just update JDBC connection URL to one like jdbc:hsqldb:hsql://localhost:1701 then then start HSQL in server mode and there should be no problems with lock file anymore.