Search code examples
mysqlplayframeworkblobh2

Cannot transfer blob from MySQL to H2


I have some blob hexadecimal values that I exported from a MySQL database using MAMP. I tried to add those values to a H2 database but I keep getting the error :

    org.h2.jdbc.JdbcSQLException: Hexadecimal string with odd number of characters: "80273753912952185238922745508880797601482513992540829416944108482201678079823009423240796439787688076562876906583780517704249256776629049440054030707230103901187860416530898080584543691951511619479802824069658267005899514817053628822676904964354186008390099680162497341280836375590099576180828248580706583256766125057680523862652582731318422096302127828322568212884418137380647350895148022669223845592468192584084729728626393575544"; SQL statement:
INSERT INTO `StatisticsExplanationActivity` VALUES(2, '2012-06-01 11:36:36', '0', '2012-06-01 11:36:37', 1, 16, 0x00aced0005737200136a6176612e7574696c2e41727261794c6973747881d21d99c7619d03000149000473697a6578700000000577040000000a7400196d757365756d507265666572656e63655f6f7269656e74616c7400166d757365756d507265666572656e63655f70686f746f740014696465616c686f6c79646179735f75726261696e7400176e696768744576656e696e67486f6262795f6d757369637400106d75736963616c54617374655f706f7078) -- (2, '2012-06-01 11:36:36', '0', '2012-06-01 11:36:37', 1, 16, 80273753912952185238922745508880797601482513992540829416944108482201678079823009423240796439787688076562876906583780517704249256776629049440054030707230103901187860416530898080584543691951511619479802824069658267005899514817053628822676904964354186008390099680162497341280836375590099576180828248580706583256766125057680523862652582731318422096302127828322568212884418137380647350895148022669223845592468192584084729728626393575544) [90003-166]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.util.StringUtils.convertHexToBytes(StringUtils.java:990)

The same INSERT line works fine with MySQL. I saw on some other topic that this may happen when the H2's multi-threaded mode is enabled. I wanted to give it a try but I have no idea how to set that parameter using Play! 1.2.x.

EDIT: Tried the MULTI_THREADED thing but still getting the same error. EDIT2: Forgot to post the hexadecimal number I used :

0xaced0005737200136a6176612e7574696c2e41727261794c6973747881d21d99c7619d03000149000473697a6578700000000577040000000a7400196d757365756d507265666572656e63655f6f7269656e74616c7400166d757365756d507265666572656e63655f70686f746f740014696465616c686f6c79646179735f75726261696e7400176e696768744576656e696e67486f6262795f6d757369637400106d75736963616c54617374655f706f7078

Solution

  • The H2 database interprets the 0x00aced0... as a number (a Java BigDecimal), and then it tries to convert the toString() representation (the decimal number) as a hex encoded binary.

    This is not what you want of course, and it fails in roughly 50% of the cases.

    So instead of 0x00aced0... you would need to use '00aced0...' (quoted)