我正在测试(尝试)squeryl 的关系建模功能
class Foo(val id: Long, val foBar: Long) extends KeyedEntity[Long]{
//Many Foo's can have one Bar.
lazy val fbar: ManyToOne[Bar] = myschema.barToFoo.right(this)
}
class Bar(val id: Long) extends KeyedEntity[Long]{
//One Bar can be assigned to many Foo's.
lazy val bfoo: OneToMany[Foo] = myschema.barToFoo.left(this)
}
object myschema extends Schema{
val bars= table[Bar]
val foo= table[Foo]
val barToFoo =
oneToManyRelation(Bar, Foo).
via((b,f) => b.id === f.foBar)
/** Find all Bars that are assigned to at least one foo.*/
def findBars() ={
from(bars)((b) => where(b.bfoo.size gt 0) select(b))
}
}
如果我尝试使用以下代码测试该代码:
test("Test findBars"){
using(jdbcSession){
val mybars = telemetria.findBars
for{i <- mybars}{
println(i.id)
i.id should equal(1)
}
}
}
我收到以下错误:
java.util.NoSuchElementException: None.get
异常是从findBars的主体中抛出的。我想不出任何可能导致此类问题的事情。有没有人遇到过类似的情况?
由于 Daniel 指出这可能是一个编译问题,因此我将附加build.properties和project.scala中的一个属性
project.organization=org.simepar
project.name=scalatra-sbt-prototype
sbt.version=0.7.4
project.version=2.0.0.M2
def.scala.version=2.8.1
build.scala.versions=2.8.1
project.initialize=false
;
val squeryl = "org.squeryl" % "squeryl_2.8.0" % "0.9.4-RC3"