Unable to use Option for a custom type

49 views
Skip to first unread message

des.m...@gmail.com

unread,
Nov 10, 2015, 2:45:02 PM11/10/15
to Squeryl
Say  have a case class that maps to table with two Timestamp fields in my database, one of which is can be null. I want to define my own custom DateTime class to map to the timestamp fields:

case class DateTime(val time: Long) extends TimestampField(new Timestamp(time)) {
    def this() = this(System.currentTimeMillis)
    def this(ts: Timestamp) = this(ts.getTime)
}

And I define my entity class thus:

case class Period(id: Int, name: String, begin: DateTime, end: Option[DateTime])

But as soon as I run my program I get the exception below. Can someone tell me that I am missing?

Thanks
Des

...
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


des.m...@gmail.com

unread,
Nov 18, 2015, 3:13:03 PM11/18/15
to Squeryl
I eventually found what I believe to be the correct approach to creating a custom type at: https://github.com/max-l/squeryl-extended-field-types-example/blob/master/src/main/scala/example/MyCustomTypes.scala

This has gotten me over the issue.
Reply all
Reply to author
Forward
0 new messages