【问题标题】:What can cause the Squeryl table object to be not found?什么会导致找不到 Squeryl 表对象?
【发布时间】:2015-02-21 01:03:57
【问题描述】:

我在尝试运行 Squeryl 示例代码时遇到编译时错误。以下代码基于 My Adventures in Coding blog post 关于使用 Squeryl 连接到 SQLServer。

import org.squeryl.adapters.MSSQLServer
import org.squeryl.{ SessionFactory, Session}
import com.company.model.Consumer

class SandBox {
  def tester() = {
    val databaseConnectionUrl = "jdbc:jtds:sqlserver://myservername;DatabaseName=mydatabasename"
    val databaseUsername = "userName"
    val databasePassword = "password"

    Class.forName("net.sourceforge.jtds.jdbc.Driver")

    SessionFactory.concreteFactory = Some(()=>
      Session.create(
        java.sql.DriverManager.getConnection(databaseConnectionUrl, databaseUsername, databasePassword),
        new MSSQLServer))

    val consumers = table[Consumer]("Consumer")
  }
}

我相信我已正确配置 build.sbt 文件以导入 Squeryl 和 JTDS 库。在添加依赖项后运行 SBT 时,它似乎下载了所需的库。

libraryDependencies ++= List (
  "org.squeryl" %% "squeryl" % "0.9.5-6",
  "net.sourceforge.jtds" % "jtds" % "1.2.4",
  Company.teamcityDepend("company-services-libs"),
  Company.teamcityDepend("ssolibrary")
) ::: Company.teamcityConfDepend("company-services-common", "test,gatling")

我确信至少有一些依赖项已成功安装。我基于 SessionFactory 代码块编译成功的事实。它只是尝试设置从 Consumer 类到 Consumer SQLServer 表的映射的行。

val consumers = table[Consumer]("Consumer")

此行会引发编译时错误。编译找不到表对象。

[info] Compiling 8 Scala sources to /Users/pbeacom/Company/integration/target/scala-2.10/classes...
[error] /Users/pbeacom/Company/integration/src/main/scala/com/company/code/SandBox.scala:25: not found: value table 
[error]     val consumers = table[Consumer]("Consumer")

使用的 Scala 版本是 2.10,如果表行被注释,则代码编译成功。在我在线研究的 Squeryl 示例中,使用 table 对象来完成数据模型映射几乎无处不在,而且似乎没有其他人遇到过类似的问题。

【问题讨论】:

    标签: scala sbt squeryl


    【解决方案1】:

    在发布并查看后不久,我终于注意到了我的问题。我对 Scala 中大量使用 mixin 的意识不够。我未能扩展 Schema 类。这就是为什么 table 在 SandBox 类的范围内是未知的。我能够通过以下类定义解决问题:

    class SandBox extends Schema {
      def tester() = {
      ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-20
      • 2012-01-05
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      相关资源
      最近更新 更多