I am trying to migrate an existing application fron SQueryl 0.9.5 to 0.9.6, in order to make use of the new extended field types. I am now to the point where the application and its tests compile, but I get a runtime error as soon as I try to load a Schema
.
A portion of the rather long stacktrace includes this:
[error] ModelSpec.withDB(ModelSpec.scala:14)
[error] BucketSpec$$anonfun$1$$anonfun$apply$1.apply(BucketSpec.scala:11)
[error] BucketSpec$$anonfun$1$$anonfun$apply$1.apply(BucketSpec.scala:11)
[error] Usupported native type models.fields.DateTime,models.fields.DateTime
[error] class java.util.UUID -> java.util.UUID --> null
[error] class java.lang.String -> java.lang.String --> null
[error] class scala.Enumeration$Value -> scala.Enumeration.Val --> null
[error] class [B -> byte[] --> null
[error] class java.lang.Float -> java.lang.Float --> null
[error] class java.util.Date -> java.util.Date --> null
[error] class scala.Enumeration$Val -> scala.Enumeration.Val --> null
[error] class java.lang.Integer -> java.lang.Integer --> null
[error] class java.lang.Double -> java.lang.Double --> null
[error] class java.sql.Timestamp -> java.sql.Timestamp --> null
[error] class java.lang.Byte -> java.lang.Byte --> null
[error] class java.lang.Boolean -> java.lang.Boolean --> null
[error] class scala.math.BigDecimal -> scala.math.BigDecimal --> null
[error] class java.lang.Long -> java.lang.Long --> null
[error] org.squeryl.internals.Utils$.throwError(Utils.scala:95)
[error] org.squeryl.internals.FieldMapper$$anonfun$get$1.apply(FieldMapper.scala:299)
[error] org.squeryl.internals.FieldMapper$$anonfun$get$1.apply(FieldMapper.scala:299)
Having a look at the source it seems that the exception comes from the failure of the FieldMapper.lookup
method, namely the line
if(!c.isPrimitive)
registry.get(c)
As far as I understand, mapping for classes are loaded via the register
method, and in particular for the native types we have the lines
protected def initialize {
import PrimitiveTypeSupport._
register(byteTEF)
register(intTEF)
register(longTEF)
register(floatTEF)
register(doubleTEF)
register(bigDecimalTEF)
register(binaryTEF)
register(booleanTEF)
register(stringTEF)
register(timestampTEF)
register(dateTEF)
register(uuidTEF)
I am not sure how to load my personal extended primitive types in this registry, so that they will be used correctly.
Does anyone know what is the mechanism through which I should enable extended primitive types?
EDIT:
Here is my model - it seems to me that it looks like the "official" example, save for the fact that I am not using directly Joda time but a thin wrapper around it, which is called DateTime
object DateTime extends PrimitiveTypeMode {
import org.squeryl._
import org.squeryl.dsl._
implicit val timeTEF = new NonPrimitiveJdbcMapper[Long, DateTime, TLong](longTEF, this) {
def convertFromJdbc(t: Long) = DateTime(t)
def convertToJdbc(t: DateTime) = t.timestamp
}
implicit val optionTimeTEF =
new TypedExpressionFactory[Option[DateTime], TOptionLong]
with DeOptionizer[Long, DateTime, TLong, Option[DateTime], TOptionLong] {
val deOptionizer = timeTEF
}
implicit def timeToTE(s: DateTime) = timeTEF.create(s)
implicit def optionTimeToTE(s: Option[DateTime]) = optionTimeTEF.create(s)
}
Corrected answer :
You are importing the org.squeryl.PrimitiveTypeMode companion object and also your own extension (object DateTime extends PrimitiveTypeMode)
You can only use on or the other in a same application (see http://squeryl.org/0.9.6.html)
The org.squeryl.PrimitiveTypeMode companion object is now deprecated (the trait with the same name isn't)
Old (wrong) answer :
You don't need to register your custom types, the register is only for primitive JDBC types, it is a closed set.
See this example : https://github.com/max-l/squeryl-extended-field-types-example JodaDate is backed by the (already registered) Timestamp primitive type.