0

I have written this very simple code

object PersonDAO {
  val db = Database.forConfig("h2mem1")
  val people = TableQuery[People]

  def checkTable() : Boolean = {
    val action = MTable.getTables
    val future = db.run(action)
    val retVal = future map {result =>
      result map {x => x}
    }

    val x = Await.result(retVal, Duration.Inf)

    if (x.length > 0) {
      true
    } else {
      false
    }
  }
}

However this always fails with error message

play.api.UnexpectedException: Unexpected exception[JdbcSQLException: Invalid value 7 for parameter columnIndex [90008-60]]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:166) ~[play_2.10-2.3.4.jar:2.3.4]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130) ~[play_2.10-2.3.4.jar:2.3.4]
    at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130) ~[play_2.10-2.3.4.jar:2.3.4]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128) ~[play_2.10-2.3.4.jar:2.3.4]
Caused by: org.h2.jdbc.JdbcSQLException: Invalid value 7 for parameter columnIndex [90008-60]
    at org.h2.message.Message.getSQLException(Message.java:84) ~[h2-1.0.60.jar:1.0.60]
    at org.h2.message.Message.getSQLException(Message.java:88) ~[h2-1.0.60.jar:1.0.60]
    at org.h2.message.Message.getInvalidValueException(Message.java:117) ~[h2-1.0.60.jar:1.0.60]
    at org.h2.jdbc.JdbcResultSet.checkColumnIndex(JdbcResultSet.java:2857) ~[h2-1.0.60.jar:1.0.60]
    at org.h2.jdbc.JdbcResultSet.get(JdbcResultSet.java:2880) ~[h2-1.0.60.jar:1.0.60]
[success] Compiled in 22ms
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
  • If you could include table definitions for `getTables `, and the associated tupled/unapply model, that'd help. – bjfletcher Jun 29 '15 at 01:55
  • MTable is a metadata structure which is provided by slick itself. I did not write the MTable http://stackoverflow.com/questions/5442034/how-could-i-know-if-a-database-table-is-exists-in-scalaquery – Knows Not Much Jun 29 '15 at 02:42
  • I'm seeing all the meta tables ok with these: val q = db.run(MTable.getTables).map(_.map(println)); println(Await.result(q, Duration.Inf)) – bjfletcher Jun 29 '15 at 02:55
  • I'm wondering if that's because h2mem doesn't have the meta tables (I'm using persist to disk h2 here and need to go just now. :) – bjfletcher Jun 29 '15 at 02:56
  • your code above gave me the same error message. So I guess I should try to use H2 in persist to disk...or perhaps postgresql for my development. – Knows Not Much Jun 29 '15 at 04:44
  • I'm using H2 and it's been really good. To use persistence, it's just a case of changing the URL for database. – bjfletcher Jun 29 '15 at 10:52
  • I changed the url to `jdbc:h2:~/test` but I got the same problem. So I guess there should be some other configuration or command which will create the metadata tables. – Knows Not Much Jun 30 '15 at 02:45
  • Could you push a project to Girhub and I can compare with my working version? – bjfletcher Jun 30 '15 at 08:34
  • https://github.com/abhitechdojo/SlickTest – Knows Not Much Jul 01 '15 at 00:34
  • Great, what command do you use to run it? – bjfletcher Jul 01 '15 at 00:58
  • `activator test` It will try to create the table and say PEOPLE already exists. if you comment out the line in HelloSpec.scala to create the table, then you will get the error mentioned above. I tested on my mac and my windows 8 PC and on both systems I got the error with `MTable.getTables` – Knows Not Much Jul 01 '15 at 01:48

1 Answers1

1

The H2 version is too old.

Change H2 version to 1.3.176 from 1.0.60 in build.sbt and the exception will go away - and the test shall pass. :)

bjfletcher
  • 11,168
  • 4
  • 52
  • 67
  • 1
    Thank you so much I was stuck here for many days. I had done a google search for "SBT h2 dependency" and then copy pasted the dependency from the search results. I think SBT should have a feature which tells you if you are using an obselete version of a library and that there is a newer version. – Knows Not Much Jul 01 '15 at 03:41