无法在 scala 上初始化类异常(可能是 squeryl bug)
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Squeryl,如果有任何 Option[_] 类型的字段,则必须定义默认构造函数。因此,对于这种情况,您将
使用
myotherclass
以便 Squeryl 可以找出 Option[_] 列的类型。请参阅此处 http:// squeryl.org/schema-definition.htmlWith Squeryl, you have to define a default constructor if you have any fields of type Option[_]. So, for this case you would have
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