Sorm示例导致错误(未找到类型)

时间:2013-08-27 04:05:20

标签: scala sorm

我无法跟随sorm website中的sorm示例 这是我的代码

import sorm._

case class Coffee(name: String, supplier: Supplier, price: Double, sales: Int, total: Int)
case class Supplier(name: String, street: String, city: String, state: String, zip: String)

object Db extends Instance(
  entities = Set(Entity[Coffee](), Entity[Supplier]()),
  url = "jdbc:mysql://address=(protocol=tcp)(host=localhost)(port=3306)(user=root)(password=test123)/test",
  initMode = InitMode.Create

)

object sormtest {
  def main(args: Array[String]): Unit = {
    val supplier1 = Supplier("Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199")
    val supplier2 = Supplier("Superior Coffee", "1 Party Place", "Mendocino", "CA", "95460")
    val supplier3 = Supplier("The High Ground", "100 Coffee Lane", "Meadows", "CA", "93966")

    println("Hello World")
    Db.save(supplier1)
  }

}

虽然代码在windows和unix上使用eclipse编译得很好,但我仍然遇到以下运行时错误:

    Hello World
Exception in thread "main" java.lang.ExceptionInInitializerError
    at sormtest$.main(sormtest.scala:23)
    at sormtest.main(sormtest.scala)
Caused by: scala.tools.reflect.ToolBoxError: reflective compilation has failed: 

not found: type Coffee
not found: type Supplier
too many arguments for constructor Object: ()Object
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:319)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:252)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:416)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.eval(ToolBoxFactory.scala:419)
    at sorm.persisted.PersistedClass$.createClass(PersistedClass.scala:99)
    at sorm.persisted.PersistedClass$$anonfun$4.apply(PersistedClass.scala:108)
    at sorm.persisted.PersistedClass$$anonfun$4.apply(PersistedClass.scala:108)
    at sext.package$$anonfun$memo$1$$anonfun$apply$3.apply(package.scala:239)
    at scala.collection.mutable.MapLike$class.getOrElseUpdate(MapLike.scala:189)
    at scala.collection.mutable.AbstractMap.getOrElseUpdate(Map.scala:91)
    at sext.package$$anonfun$memo$1.apply(package.scala:239)
    at sorm.persisted.PersistedClass$.apply(PersistedClass.scala:111)
    at sorm.Instance$Initialization$$anonfun$9$$anonfun$apply$17.apply(Instance.scala:233)
    at sorm.Instance$Initialization$$anonfun$9$$anonfun$apply$17.apply(Instance.scala:233)
    at embrace.package$EmbraceAny$.$$extension(package.scala:6)
    at sorm.Instance$Initialization$$anonfun$9.apply(Instance.scala:233)
    at sorm.Instance$Initialization$$anonfun$9.apply(Instance.scala:233)
    at scala.collection.immutable.Set$Set2.foreach(Set.scala:94)
    at sorm.Instance$Initialization.<init>(Instance.scala:233)
    at sorm.Instance.<init>(Instance.scala:29)
    at Db$.<init>(sormtest.scala:6)
    at Db$.<clinit>(sormtest.scala)
    ... 2 more

我知道为什么我找不到类型错误?

编辑:

基于来自@ nikita-volkov的评论,我将案例类移到了sormtest中,这解决了我的问题,这里是代码

object sormtest {

    import sorm._

    case class Coffee(name: String, supplier: Supplier, price: Double, sales: Int, total: Int)
    case class Supplier(name: String, street: String, city: String, state: String, zip: String)

    object Db extends Instance(
      entities = Set(Entity[Coffee](), Entity[Supplier]()),
      url = "jdbc:mysql://address=(protocol=tcp)(host=localhost)(port=3306)(user=root)(password=test123)/test",
      initMode = InitMode.Create

    )


    def main(args: Array[String]): Unit = {
        val supplier1 = Supplier("Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199")
        val supplier2 = Supplier("Superior Coffee", "1 Party Place", "Mendocino", "CA", "95460")
        val supplier3 = Supplier("The High Ground", "100 Coffee Lane", "Meadows", "CA", "93966")

        println("Hello World")
        Db.save(supplier1)
    }

}

0 个答案:

没有答案