Error with BLOB-Files in Client/Server mode

23 views
Skip to first unread message

Thomet

unread,
Oct 18, 2010, 7:21:37 AM10/18/10
to H2 Database
Hello,
I have an application where I safe blob data in the database. The
application can run in embedded or server mode. With H2-Embedded mode
it works fine but with the server mode I have a problem with openening
the blob files.

When I do this:

ObjectInputStream in = new ObjectInputStream(bob.getBinaryStream());

I get this error:

org.h2.jdbc.JdbcSQLException: File corrupted while reading record: "C:
\Users\thomet\AppData\Local\Temp\h2.temp.29541a7d91bbf836.12.temp.db".
Possible solution: use the recovery tool [90030-144]

I have read that BLOB files are cached to garanty a faster local
access. That seems to be the problem.

The server starts with:

args = new String[] {"-tcpSSL", "-tcpPort", tcpPort, "-tcpPassword",
tcpPassword, "-tcpAllowOthers", "-baseDir", baseDir};
try {
h2Server = Server.createTcpServer(args);
} catch(SQLException e) {
e.printStackTrace();
}

and i have tried this option:

System.setProperty("h2.lobInDatabase", "true");

but nothing helps.

Greetings thomet

mf

unread,
Oct 21, 2010, 7:31:11 AM10/21/10
to H2 Database
Hi all,

i have looked a little further into the problem my co-worker is
having:

the problem seems to be the following:

we use something like:

1 Session session = hbds.getSessionFactory().openSession();
2 session.beginTransaction();
3 Query query = session.createQuery(querystring);
4 session.getTransaction().commit();
5 List<?> results = query.list();
6 session.flush();
7 session.disconnect();
8 Object oneResult = results.get(0);

And oneResult is a single Blob (the real scenario is a little more
complicated, but this should show our issue) to be more precise it is
a JdbcBlob containing a ValueLobDb value. We now try to use the Blobs
content (image data) but the ValueLobDb deleted its tempfile (in
query.list() in line 5) and thus when trying to access the actual Blob
data we want, the tempfile is gone and as blob.getBinaryStream() tries
to access it, the (somewhat misleading) error ("File corrupted...") is
thrown because of the missing file. Any idea, what to do here?

gr

mf

Sergi Vladykin

unread,
Oct 21, 2010, 9:59:29 AM10/21/10
to H2 Database
Hi,

It's incorrect to use LOB values after connection close in any dbms
not only H2. Even if H2 currenctly saves LOBs to temp files (which is
incorrect and I belive this will be changed sooner or later) you can
not rely on this behaviour because LOB typically will depend on its
connection in one or another way. I guess with most of other dbms you
will have errors with your scenario too. So the correct approach to
work with Connection dependent resources (like PreparedStatements,
ResultSets, Blobs, Clobs etc) only while respective connections are
opened.

regards,
Sergi
Reply all
Reply to author
Forward
0 new messages