Search code examples
scalaplayframework-2.0squeryl

Scala timestamp/date zero argument constructor?


Squeryl requires a zero argument constructor when using Option[] in fields. I realized how I could create such a constructor for Long like 0L but how do I create such a thing for a Timestamp or Date?

Essentially I need to finish this:

def this() = this(0L,"",TIMESTAMP,TIMESTAMP,0L,"","","","",Some(""),Some(""),"",DATE,DATE,false,false,false,Some(0L),Some(0),Some(0L))

Below is how I originally found the timestamp and date problem.

Background

Getting the following error in my Play! 2.0 Scala app (also using Squeryl):

Caused by: java.lang.RuntimeException: Could not deduce Option[] type of field 'startOrder' of class models.Job

This field in models.Job:

@Column("start_order")
var startOrder: Option[Int],

And in the Postgres DB it is defined as an integer. Is there different handling in Play! 2.0 of models, is this a bug, or is it a Squeryl problem? Thanks!

Stack trace, looks like Squeryl problem

Caused by: java.lang.RuntimeException: Could not deduce Option[] type of field 'startOrder' of class models.Job
        at scala.sys.package$.error(package.scala:27) ~[scala-library.jar:na]
        at scala.Predef$.error(Predef.scala:66) ~[scala-library.jar:0.11.2]
        at org.squeryl.internals.FieldMetaData$$anon$1.build(FieldMetaData.scala:441) ~[squeryl_2.9.1-0.9.4.jar:na]
        at org.squeryl.internals.PosoMetaData$$anonfun$3.apply(PosoMetaData.scala:111) ~[squeryl_2.9.1-0.9.4.jar:na]
        at org.squeryl.internals.PosoMetaData$$anonfun$3.apply(PosoMetaData.scala:80) ~[squeryl_2.9.1-0.9.4.jar:na]
        at scala.collection.immutable.HashMap$HashMap1.foreach(HashMap.scala:176) ~[scala-library.jar:0.11.2]

Solution

  • If startOrder is defined as

    val startOrder: Option[java.sql.Timestamp]
    

    in class definition. I believe,

    Some(new java.sql.Timestamp(0))
    

    should be passed to constructor.