SormException unsupported type

151 Views Asked by At

I have the following model:

package models

import java.net.URL
import play.api.Logger
import play.api.libs.json.Json

case class Page(url: String) {
  var content: String = new URL(url).getContent().toString
  Logger.info("Content is: " + content)
}

object Page {
  implicit val personFormat = Json.format[Page]
}

The database representation code is this:

package models

import sorm._

object Db extends Instance(entities = Seq(Entity[Page]()), url="jdbc:h2:mem:test")

I am getting the following error:

[error] - play.core.server.netty.PlayDefaultUpstreamHandler - Cannot invoke the action
[info] java.lang.RuntimeException: java.lang.ExceptionInInitializerError

A bit lower in the stack trace:

[info] Caused by: sorm.core.SormException: Unsupported type: (x$1: String)scala.Unit
[info]  at sorm.mappings.MappingKind$.apply(MappingKind.scala:85) ~[sorm-0.3.19.jar:na]
[info]  at sorm.mappings.Mapping$.apply(Mapping.scala:69) ~[sorm-0.3.19.jar:na]
[info]  at sorm.mappings.Mapping$.apply(Mapping.scala:97) ~[sorm-0.3.19.jar:na]
[info]  at sorm.mappings.EntityMapping$$anonfun$properties$1.apply(EntityMapping.scala:18) ~[sorm-0.3.19.jar:na]
[info]  at sorm.mappings.EntityMapping$$anonfun$properties$1.apply(EntityMapping.scala:18) ~[sorm-0.3.19.jar:na]

Therefore, I think there is an issue with Sorm but I can't realise what the problem is.

I'm not sure how Sorm works, but I doubt it doesn't support Strings?

1

There are 1 best solutions below

4
Nikita Volkov On BEST ANSWER

Just remove the weird stuff you have in the constructor and you're all good. Model by definition is supposed to be only about data. You have implanted a side-effect of fetching from some URL, which is a mistake from the design standpoint either way.