光滑索引会导致抛出InvocationTargetException

时间:2015-03-03 05:53:54

标签: scala slick

我有以下Slick Table定义:

class FooRecords(tag: Tag) extends Table[Foo](tag, Foo.TableName) {
  def id = column[Int]("ID", O.PrimaryKey)
  def teamId = column[Int]("TEAM_ID")
  // ... other columns
  def * = (id, teamId, /* ... */) <> ((FooRecord.apply _).tupled, FooRecord.unapply)
  def teamIdIdx = index("team_id_idx", teamId, unique = false)
}

// ...

val fooRecords = TableQuery[FooRecords]
fooRecords.ddl.createStatements.foreach(x => info(x))

如果def teamIdIdx行被注释,它可以正常工作(但显然没有创建索引)。如果没有评论,我会得到InvocationTargetException

 Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at scala.slick.lifted.AbstractTable$$anonfun$indexes$2.apply(AbstractTable.scala:105)
        at scala.slick.lifted.AbstractTable$$anonfun$indexes$2.apply(AbstractTable.scala:103)
        at scala.collection.TraversableViewLike$Mapped$$anonfun$foreach$2.apply(TraversableViewLike.scala:169)
        at scala.collection.TraversableViewLike$Filtered$$anonfun$foreach$4.apply(TraversableViewLike.scala:197)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.IndexedSeqLike$$anon$1.foreach(IndexedSeqLike.scala:52)
        at scala.collection.TraversableViewLike$Filtered$class.foreach(TraversableViewLike.scala:196)
        at scala.collection.mutable.IndexedSeqView$$anon$1.foreach(IndexedSeqView.scala:80)
        at scala.collection.TraversableViewLike$Mapped$class.foreach(TraversableViewLike.scala:168)
        at scala.collection.SeqViewLike$$anon$3.foreach(SeqViewLike.scala:197)
        at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:59)
        at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:104)
        at scala.collection.ViewMkString$class.thisSeq(TraversableViewLike.scala:22)
        at scala.collection.SeqViewLike$AbstractTransformed.thisSeq(SeqViewLike.scala:37)
        at scala.collection.SeqViewLike$$anonfun$sortBy$1.apply(SeqViewLike.scala:266)
        at scala.collection.SeqViewLike$$anonfun$sortBy$1.apply(SeqViewLike.scala:266)
        at scala.collection.SeqViewLike$$anon$1.<init>(SeqViewLike.scala:195)
        at scala.collection.SeqViewLike$class.newForced(SeqViewLike.scala:195)
        at scala.collection.SeqViewLike$AbstractTransformed.newForced(SeqViewLike.scala:37)
        at scala.collection.SeqViewLike$class.sortBy(SeqViewLike.scala:266)
        at scala.collection.SeqViewLike$AbstractTransformed.sortBy(SeqViewLike.scala:37)
        at scala.slick.lifted.AbstractTable.indexes(AbstractTable.scala:105)
        at scala.slick.driver.JdbcStatementBuilderComponent$TableDDLBuilder.<init>(JdbcStatementBuilderComponent.scala:597)
        at scala.slick.driver.SQLiteDriver$TableDDLBuilder.<init>(SQLiteDriver.scala:192)
        at scala.slick.driver.SQLiteDriver$class.createTableDDLBuilder(SQLiteDriver.scala:133)
        at scala.slick.driver.SQLiteDriver$.createTableDDLBuilder(SQLiteDriver.scala:260)
        at scala.slick.driver.SQLiteDriver$.createTableDDLBuilder(SQLiteDriver.scala:260)
        at scala.slick.driver.JdbcProfile$class.buildTableSchemaDescription(JdbcProfile.scala:39)
        at scala.slick.driver.SQLiteDriver$.buildTableSchemaDescription(SQLiteDriver.scala:260)
        at scala.slick.driver.SQLiteDriver$.buildTableSchemaDescription(SQLiteDriver.scala:260)
        at scala.slick.profile.RelationalProfile$TableQueryExtensionMethods.ddl(RelationalProfile.scala:52)

我在Android 19上"com.typesafe.slick" %% "slick" % "2.1.0"

1 个答案:

答案 0 :(得分:0)

这是因为Proguard取消了index方法。使用以下内容调整build.sbt

proguardOptions in Android ++= Seq(
  "-keep class scala.slick.lifted.**",
  // ...
}

帮助。