The getOrElse(null) is causing your problem. This is because you're calling getOrElse on an Option[Float]. However null in Scala cannot be assigned to a value type like Float. From the scaladoc:

Null is a subtype of all reference types; its only instance is the null reference. Since Null is not a subtype of value types, null is not a member of any such type. For instance, it is not possible to assign null to a variable of type scala.Int.

The same statement applies to Float. Since null and Float do not have a common super-type (other than Any), Scala infers the as Any instead Float. This was allowed in Play 2.2.x, however in 2.3.x, Any is no longer allowed to be passed as a parameter because it is not type safe.

The solution? Just remove the getOrElse(null)s and you're good to go. is an Option[Float] which Anorm knows how to handle whether it's empty or not. In general, using null in Scala is bad practice. If you see yourself calling getOrElse(null), you should ask yourself if perhaps there's a better way to handle it safely.



val ps = Seq[anorm.ParameterValue](yourParameter1,yourParameter2) // Seq[ParameterValue]
SQL("SELECT * FROM test WHERE a={a} b={b}").
  on('a -> ps(0), 'b -> ps(1))

You are using parameter of Any(or someother) type but the doc says to use anorm.ParameterValue type



I would suggest to first try val p: ParameterValue = caller.

I think the issue is more that there is no specific parameter conversion for Tuple2[Float,Float] (btw (Float, Float)).

Before Anorm 2.3, unsafe conversion was using .toString (which can lead to a lot of issue).

The better is to convert the tuple to a formatted string, either before passing it as parameter or by adding a custom parameter conversion.

(Anorm doc indicates type safety issues, and how to implement conversion)

Related Query

More Query from same tag