From b294b033bb49840da318c30bf6eb8be2540696e9 Mon Sep 17 00:00:00 2001 From: Jacek Centkowski Date: Thu, 24 Oct 2013 07:24:52 -0700 Subject: [PATCH] Get rid of JdbcSQLException while numbers are read from cache Exception org.h2.jdbc.JdbcSQLException: Hexadecimal string with odd number of characters: "0" is thrown when number with value 0 or string with value "0" is stored in H2Cache and read is performed. The fix modifies implementation so that Java de-serialization is performed even for built-in (e.g. Integer) types. Change-Id: I953487cb75b3712e8825a74613977425873507a1 Signed-off-by: Jacek Centkowski --- .../java/com/google/gerrit/server/cache/h2/H2CacheImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java b/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java index a196b07054..4428034817 100644 --- a/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java +++ b/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java @@ -27,6 +27,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; +import java.sql.Types; import java.util.Calendar; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; @@ -267,7 +268,7 @@ public class H2CacheImpl extends AbstractLoadingCache { } void set(PreparedStatement ps, int col, K value) throws SQLException { - ps.setObject(col, value); + ps.setObject(col, value, Types.JAVA_OBJECT); } Funnel funnel() { @@ -488,7 +489,7 @@ public class H2CacheImpl extends AbstractLoadingCache { } try { keyType.set(c.put, 1, key); - c.put.setObject(2, holder.value); + c.put.setObject(2, holder.value, Types.JAVA_OBJECT); c.put.setTimestamp(3, new Timestamp(holder.created)); c.put.setTimestamp(4, new Timestamp(System.currentTimeMillis())); c.put.executeUpdate();