假设我有一个case类,它映射到我的数据库中有两个Timestamp字段的表,其中一个可以为null。我想定义自己的自定义DateTime类来映射到时间戳字段:
case class DateTime(val time: Long) extends TimestampField(new Timestamp(time)) {
def this() = this(System.currentTimeMillis)
def this(ts: Timestamp) = this(ts.getTime)
}
我定义了我的实体类:
case class Period(id: Int, name: String, begin: DateTime, end: Option[DateTime])
但是一旦我运行我的程序,我就会得到以下例外。有人能告诉我我错过了什么吗?
...
Caused by: java.lang.RuntimeException: error while reflecting on metadata for (Some(private final scala.Option data.Period.end),Some(public scala.Option data.Period.end()),None,Set()) of class data.Period
at org.squeryl.internals.PosoMetaData$$anonfun$6.apply(PosoMetaData.scala:126)
at org.squeryl.internals.PosoMetaData$$anonfun$6.apply(PosoMetaData.scala:83)
at scala.collection.immutable.HashMap$HashMap1.foreach(HashMap.scala:221)
at scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:428)
at scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:428)
at org.squeryl.internals.PosoMetaData.<init>(PosoMetaData.scala:83)
at org.squeryl.View.<init>(View.scala:64)
at org.squeryl.Table.<init>(Table.scala:29)
at org.squeryl.Schema.table(Schema.scala:345)
at org.squeryl.Schema.table(Schema.scala:341)
at data.Library$.<init>(Library.scala:211)
at data.Library$.<clinit>(Library.scala)
... 17 more
Caused by: java.lang.RuntimeException: class data.Period used in table Period, needs a zero arg constructor with sample values for Option[] field end
at org.squeryl.internals.Utils$.throwError(Utils.scala:95)
at org.squeryl.internals.FieldMetaData$$anon$1.build(FieldMetaData.scala:490)
at org.squeryl.internals.PosoMetaData$$anonfun$6.apply(PosoMetaData.scala:118)
... 28 more