Hi,
I have a Java application that uses a H2Database with Hibernate. The
problem is, sometimes this database gets corrupted. Probably the
problem is mine, because sometimes there are power failures so the
application is not properly closed. It cannot be avoided.
But after accepting that the database will be sometimes corrupted, is
there any way to recover it as much as posible?
I have read that the recovery tool will be helpful, but on
http://www.h2database.com/html/advanced.html it says that "The recover
tool can be used to extract the contents of a data file[...]". As data
file it means the whole database? If I run the recovery tool and then
do a runscript, the database will be recovered? Should I delete the
lock file first?
In case the type of corruption is relevant, the exception trace is
this:
org.hibernate.exception.GenericJDBCException: Cannot open connection
at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException
(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert
(SQLStateConverter.java:114)
[...]
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.h2.jdbc.JdbcSQLException: General error:
java.lang.RuntimeException: rowcount remaining=-49 SYS [50000-100]
at org.h2.message.Message.getSQLException(Message.java:103)
at org.h2.message.Message.convert(Message.java:257)
at org.h2.engine.Database.<init>(Database.java:231)
at org.h2.engine.Engine.openSession(Engine.java:57)
at org.h2.engine.Engine.openSession(Engine.java:126)
at org.h2.engine.Engine.getSession(Engine.java:109)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:111)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: rowcount remaining=-49 SYS
at org.h2.message.Message.getInternalError(Message.java:179)
at org.h2.table.TableData.addIndex(TableData.java:202)
at org.h2.engine.Database.open(Database.java:582)
at org.h2.engine.Database.<init>(Database.java:212)
... 5 more
at org.h2.engine.SessionRemote.done(SessionRemote.java:493)
at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:
111)
at org.h2.engine.SessionRemote.connectServer
(SessionRemote.java:316)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer
(SessionRemote.java:227)
at org.h2.engine.SessionRemote.createSession
(SessionRemote.java:221)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:103)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:87)
at org.h2.Driver.connect(Driver.java:57)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at
org.hibernate.connection.DriverManagerConnectionProvider.getConnection
(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection
(ConnectionManager.java:446)
... 24 more
Thanks :)