【问题标题】:Slick index causes InvocationTargetException to be thrown光滑的索引导致 InvocationTargetException 被抛出
【发布时间】:2015-03-03 18:30:57
【问题描述】:

我有以下 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)

我在"com.typesafe.slick" %% "slick" % "2.1.0" 使用 Android 19。

【问题讨论】:

  • InvocationException 总是包含一个更有趣且信息量更大的原因 (e.getCause())。
  • 好提示,由于 Proguard,这是一个缺少的方法 index

标签: scala slick


【解决方案1】:

这是由于 Proguard 取消了 index 方法。调整build.sbt

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

帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多