我通过使用Slick对oracle表进行插入查询时遇到了一个非常难以理解的问题。我不知道如何定位错误。
"com.typesafe.slick" %% "slick" % "2.1.0",
"com.typesafe.slick" %% "slick-extensions" % "2.1.0"
通过插入,我总是得到这个例外:
[DEBUG] - from [scala.slick.jdbc.JdbcBackend.statement] in [pool-1-thread-1] - [Preparing insert statement: insert into "NOTIFICATION_MESSAGE" ("CLIENT_ID","IMPORTANCE","TYPE_ID","ACCOUNT","TITLE","MESSAGE","STATUS","CREATION_DATE") values (?,?,?,?,?,?,?,?), returning: ID]
[ERROR] - from [mypackage.db.core.OracleDatabaseComponent] in [pool-1-thread-1] - [DB operation failed - error: [An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: 8]]
mypackage.db.core.DBProcessException: DB operation failed - error: [An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: 8]
但最奇怪的是,如果我从插入查询中删除一个参数(将作为默认值填充),它将成功执行。 它看起来像插入查询中的值数量的限制,但是其他表(其中一些有超过8列)没有问题。 也许有人遇到过这个问题或知道如何本地化错误?
表ddl:
create table NOTIFICATION_MESSAGE (
id number(20) not null,
client_id nvarchar2(32) not null,
importance number(1) default 1 not null,
type_id number(2) not null,
account nvarchar2(32),
title nvarchar2(255) not null,
message nvarchar2(2000) not null,
status nvarchar2(32) default 'NEW' not null,
creation_date date default sysdate not null
)
光滑的模型:
import com.typesafe.slick.driver.oracle.OracleDriver.simple._
case class NotificationMessage(
id: Option[Long],
clientId: String,
importance: Int = 1,
typeId: Int,
account: Option[String],
title: String,
message: String,
status: NotificationStatus,
creationDate: Instant
)
class NotificationMessageTable(tag: Tag) extends Table[NotificationMessage](tag, "NOTIFICATION_MESSAGE") {
def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
def clientId = column[String]("CLIENT_ID", O.NotNull)
def importance = column[Int]("IMPORTANCE", O.NotNull)
def typeId = column[Int]("TYPE_ID", O.NotNull)
def account = column[Option[String]]("ACCOUNT")
def title = column[String]("TITLE", O.NotNull)
def message = column[String]("MESSAGE", O.NotNull)
def status = column[NotificationStatus]("STATUS", O.NotNull)
def creationDate = column[Instant]("CREATION_DATE", O.NotNull)
override def * : ProvenShape[NotificationMessage] =
(id.?, clientId, importance, typeId, account, title, message, status, creationDate) <>
(NotificationMessage.tupled, NotificationMessage.unapply)
}
答案 0 :(得分:-1)
删除ID。?
只是id。该列未标记为可选。
如您所见,插入中仅使用了8个参数。