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

发布于 2024-10-18 08:50:32 字数 1580 浏览 2 评论 0原文

我正在使用 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

如果我尝试在 sbt 的控制台上快速运行以下代码,我会得到一个错误:

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

错误:

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

正如我所期望的,无论我尝试在该模式上调用什么方法,都会弹出错误。

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

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))
...
}

这是我的代码表的样子:

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)}
}

最后是我的 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)
);

我还没有将第三个表映射到我的代码中。可能发生什么事?

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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒗幽 2024-10-25 08:50:32

使用 Squeryl,如果有任何 Option[_] 类型的字段,则必须定义默认构造函数。因此,对于这种情况,您将

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

使用 myotherclass 以便 Squeryl 可以找出 Option[_] 列的类型。请参阅此处 http:// squeryl.org/schema-definition.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文