开发者

Could not initialize class exception on scala(possibly squeryl bug)

I am developing a web application with scala 2.8.1, scalatra 2.0.0.M2, squeryl 2.8.0 and scalate 2.0.0 and sbt

I am开发者_JAVA技巧 having a problem with, apparently a model or the schema class. When I run my tests I get a:

java.lang.NoClassDefFoundError: Could not initialize class org.mycompany.myproject.model.myschema

If I try to run the following code on sbt's console-quick I get an error:

import org.mycompany.myproject.model.myschema
myschema.mytable

Error:

java.lang.RuntimeException: Could not deduce Option[] type of field 'field1' of class org.mycompany.myproject.model.myotherclass

As I have expected the error pops up no matter what method I try to invoke on that schema.

Now here is how my schema looks like near that table declaration:

object myschema extends Schema {
  val myotherclasses = table[myotherclass]
  val otherClassManyToMany = manyToManyRelation(yetanotherclass, mytables).
       via[myotherclass]((e,ssr, sse) => (e.id === sse.leftId, sse.rightId === ssr.id))
...
}

This is how my code table looks like:

class myotherclass(
  val rightId: Long,
  val field1: Option[Long],
  val field2: Option[Long],
  val foreiginKey: Long,
  val leftId: Long) extends KeyedEntity[CompositeKey2[Long, Long]] {
  def id ={compositeKey(sesestacao, sessensor)}
}

And finally my sql definition:

create table telemetria.myotherclass (
  rightId numeric(8,0) references telemetria.estacao(estcodigo),
  field1 numeric(8,0),
  field2 numeric(8,0),
  foreiginKey smallint references myschema.thirdtable(idOfThird),
  leftId smallint references myschema.yetanotherclass(id),
  primary key (rightId, leftId)
);

I have not mapped the thirdtable into my code. What could be going on?


With Squeryl, you have to define a default constructor if you have any fields of type Option[_]. So, for this case you would have

def this() = this(0l, Some(0l), Some(0l), 0l, 0l)

on myotherclass so that Squeryl can figure out the type of the Option[_] columns. See the section labeled Nullable columns are mapped with Option[] fields here http://squeryl.org/schema-definition.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜