H2 in-memory database error "Data conversion error converting" when using UUID as primary key
<p>I got the following error when using UUID as primary key with Slick with H2 in-memory database. I've tried to debug this for days, but no luck:</p>
<pre><code>Data conversion error converting &quot;00000000-0000-0000-0000-000000000001&quot;
</code></pre>
<p>Here's the code that can reproduce this issue:</p>
<pre><code>import java.util.UUID

import slick.driver.H2Driver.api._

import scala.concurrent.Await
import scala.concurrent.duration.Duration

object Main {

  class Tasks(tag: Tag) extends Table[(String, Option[UUID])](tag, &quot;tasks&quot;) {
    def name: Rep[String] = column[String](&quot;name&quot;)

    def id = column[UUID](&quot;id&quot;, O.SqlType(&quot;UUID&quot;), O.PrimaryKey, O.AutoInc)

    def * = (name, id ?)
  }

  def main(args: Array[String]) {
    val db = Database.forURL(&quot;jdbc:h2:mem:test;MODE=PostgreSQL&quot;, driver = &quot;org.h2.Driver&quot;)

    try {
      val tasks = TableQuery[Tasks]
      println(&quot;Create table: &quot; + tasks.schema.create.statements.mkString(&quot;|&quot;))
      val setupAction: DBIO[Unit] = DBIO.seq(
        tasks.schema.create,
        tasks.+=(&quot;foo&quot;, None)
      )

      Await.result(db.run(setupAction), Duration.Inf)
    } finally db.close
  }
}
</code></pre>
<p>Can anyone provide some help here?</p>
<p><strong>--- Updates ---</strong></p>
<p>The table creation query is like:</p>
<pre><code>create table &quot;tasks&quot; (
  &quot;name&quot; VARCHAR                                              NOT NULL,
  &quot;id&quot;   UUID GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY
);
</code></pre>
<p>The full stack trace is like:</p>
<pre><code>Exception in thread &quot;main&quot; org.h2.jdbc.JdbcSQLException: Data conversion error converting &quot;00000000-0000-0000-0000-000000000001&quot;; SQL statement:
insert into &quot;tasks&quot; (&quot;name&quot;)  values (?) [22018-187]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:168)
    at org.h2.value.Value.convertTo(Value.java:902)
    at org.h2.value.Value.getLong(Value.java:443)
    at org.h2.table.Column.updateSequenceIfRequired(Column.java:339)
    at org.h2.table.Column.validateConvertUpdateSequence(Column.java:331)
    at org.h2.table.Table.validateConvertUpdateSequence(Table.java:737)
    at org.h2.command.dml.Insert.insertRows(Insert.java:151)
    at org.h2.command.dml.Insert.update(Insert.java:114)
    at org.h2.command.CommandContainer.update(CommandContainer.java:78)
    at org.h2.command.Command.executeUpdate(Command.java:254)
    at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:157)
    at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:143)
    at slick.driver.JdbcActionComponent$InsertActionComposerImpl$SingleInsertAction$$anonfun$run$7.apply(JdbcActionComponent.scala:507)
    at slick.driver.JdbcActionComponent$InsertActionComposerImpl$SingleInsertAction$$anonfun$run$7.apply(JdbcActionComponent.scala:504)
    at slick.jdbc.JdbcBackend$SessionDef$class.withPreparedStatement(JdbcBackend.scala:347)
    at slick.jdbc.JdbcBackend$BaseSession.withPreparedStatement(JdbcBackend.scala:407)
    at slick.driver.JdbcActionComponent$InsertActionComposerImpl.preparedInsert(JdbcActionComponent.scala:498)
    at slick.driver.JdbcActionComponent$InsertActionComposerImpl$SingleInsertAction.run(JdbcActionComponent.scala:504)
    at slick.driver.JdbcActionComponent$SimpleJdbcDriverAction.run(JdbcActionComponent.scala:32)
    at slick.driver.JdbcActionComponent$SimpleJdbcDriverAction.run(JdbcActionComponent.scala:29)
    at slick.dbio.DBIOAction$$anon$4$$anonfun$run$3.apply(DBIOAction.scala:214)
    at slick.dbio.DBIOAction$$anon$4$$anonfun$run$3.apply(DBIOAction.scala:214)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at slick.dbio.DBIOAction$$anon$4.run(DBIOAction.scala:214)
    at slick.dbio.DBIOAction$$anon$4.run(DBIOAction.scala:212)
    at slick.backend.DatabaseComponent$DatabaseDef$$anon$2.liftedTree1$1(DatabaseComponent.scala:237)
    at slick.backend.DatabaseComponent$DatabaseDef$$anon$2.run(DatabaseComponent.scala:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NumberFormatException: For input string: &quot;00000000-0000-0000-0000-000000000001&quot;
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Long.parseLong(Long.java:589)
    at java.lang.Long.parseLong(Long.java:631)
    at org.h2.value.Value.convertTo(Value.java:854)
    ... 31 more
</code></pre>