通过JOOQ插入Scala Enum

时间:2016-05-26 14:53:08

标签: mysql scala enums jooq

我使用JOOQ生成器创建了我的Mysql数据库模式的映射, 它在我的枚举列上创建一个枚举,但当我尝试将值插入数据库时​​,我收到错误。

这是枚举:

object Operationtype {

  val Read : Operationtype = enums.Read
  val Write : Operationtype = enums.Write

  def values() : Array[Operationtype] = Array(
      Read
    , Write
  )

  def valueOf(s : String) : Operationtype = s match {
    case "Read" => Read
    case "Write" => Write
    case _ => throw new IllegalArgumentException()
  }
}

sealed trait Operationtype extends EnumType {
  override def getSchema : Schema = null
  override def getName : String = "Operationtype"
}

case object Read extends Operationtype {
  override def getLiteral : String = "Read"
}

case object Write extends Operationtype {
  override def getLiteral : String = "Write"
}

这是使用枚举的列类型(我已将Table特定记录类型更改为org.jooq.Record)

 val OPERATIONTYPE : TableField[Record, Operationtype] =
 createField("OperationType",
 org.jooq.util.mysql.MySQLDataType.VARCHAR.asEnumDataType(classOf[enums.Operationtype]),
 "")

这是给我错误的代码:

 DSL.using(conn, SQLDialect.MYSQL).insertInto(Tables.TEST,
 Test.TEST.OPERATIONTYPE)   .values(Operationtype.Read)    .execute()

这是错误:

  

线程“main”中的异常org.jooq.exception.MappingException:不能   创建类enums的实例。阅读$       at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:787)       在org.jooq.impl.DSL.mostSpecific(DSL.java:15189)       在org.jooq.impl.DSL.val(DSL.java:15157)       在org.jooq.impl.DSL.val(DSL.java:15125)       在org.jooq.impl.Tools.field(Tools.java:1022)       在org.jooq.impl.AbstractStoreQuery.addValue(AbstractStoreQuery.java:83)       在org.jooq.impl.InsertImpl.addValue(InsertImpl.java:295)       在org.jooq.impl.InsertImpl.values(InsertImpl.java:274)       在org.jooq.impl.InsertImpl.values(InsertImpl.java:158)       在org.jooq.impl.InsertImpl.values(InsertImpl.java:91)       在DbMain $ .main(DbMain.scala:21)       在DbMain.main(DbMain.scala)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:497)       在com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)   引起:org.jooq.exception.MappingException:查找时出错   Scala enum       在org.jooq.impl.Tools.enums(Tools.java:3197)       at org.jooq.impl.DefaultDataType.asEnumDataType(DefaultDataType.java:661)       at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:783)       ... 16更多引起:java.lang.ClassNotFoundException

0 个答案:

没有答案