无法初始化scala上的类异常(可能是squeryl bug)

Mar*_*rda 2 scala sbt squeryl

我正在使用scala 2.8.1,scalatra 2.0.0.M2,squeryl 2.8.0和scalate 2.0.0以及sbt开发Web应用程序

我遇到了问题,显然是模型或架构类.当我运行我的测试时,我得到一个:

java.lang.NoClassDefFoundError: Could not initialize class org.mycompany.myproject.model.myschema
Run Code Online (Sandbox Code Playgroud)

如果我尝试在sbt的console-quick上运行以下代码,我会收到一个错误:

import org.mycompany.myproject.model.myschema
myschema.mytable
Run Code Online (Sandbox Code Playgroud)

错误:

java.lang.RuntimeException: Could not deduce Option[] type of field 'field1' of class org.mycompany.myproject.model.myotherclass
Run Code Online (Sandbox Code Playgroud)

正如我所料,无论我尝试在该架构上调用什么方法,都会弹出错误.

现在,这是我的架构在该表声明附近的样子:

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))
...
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码表的样子:

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)}
}
Run Code Online (Sandbox Code Playgroud)

最后我的sql定义:

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)
);
Run Code Online (Sandbox Code Playgroud)

我没有将第三个表格映射到我的代码中.会发生什么事?

Tho*_*ney 5

使用Squeryl时,如果您有任何类型为Option [_]的字段,则必须定义默认构造函数.所以,对于这种情况你会有

def this() = this(0l, Some(0l), Some(0l), 0l, 0l)
Run Code Online (Sandbox Code Playgroud)

myotherclass以便Squeryl可以计算出选项[_]列的类型.请参阅标有Nullable列的部分,在此处使用Option []字段进行映射http://squeryl.org/schema-definition.html