1

我正在尝试使用slick codegen根据 SQLServer 中的现有数据创建一个 Tables.scala 文件,并具有以下设置:

slick.codegen.SourceCodeGenerator.main(Array("slick.jdbc.SQLServerProfile", 
                                             "com.microsoft.sqlserver.jdbc.SQLServerDriver",
                                             "jdbc:sqlserver://myserver.com:1433;applicationName=TestCodeGen;integratedSecurity=true;authenticationScheme=NativeAuthentication;databaseName=MYDB", 
                                             "src/main/scala/", 
                                             "com.mypackage", 
                                             "myUserId", 
                                             ""))

当我运行命令时,我没有收到任何错误,但会生成一个空的 Tables.scala 文件(数据库中有几十个表):

package com.mypackage
// AUTO-GENERATED Slick data model
/** Stand-alone Slick data model for immediate use */
object Tables extends {
  val profile = slick.jdbc.SQLServerProfile
} with Tables

/** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */
trait Tables {
  val profile: slick.jdbc.JdbcProfile
  import profile.api._
  import slick.model.ForeignKeyAction

  /** DDL for all tables. Call .create to execute. */
  lazy val schema: profile.SchemaDescription = profile.DDL(Nil, Nil)
  @deprecated("Use .schema instead of .ddl", "3.0")
  def ddl = schema
}

我的怀疑是 SQLServer 使用 dbo 模式这一事实存在问题,但该模式未在 codegen 调用的任何地方指定(所有表都命名为“dbo..TableName”)。

所以我的问题是:我是否需要在 codegen 配置中的某处指定“dbo”,如果需要,怎么做?

如果答案是不需要做任何事情,那么我如何调试 codegen 显然失败但没有产生错误的事实?

预先感谢您的考虑和回复。

4

1 回答 1

1

尽管对于直接连接,com.microsoft 驱动程序确实可以工作,但我发现对于代码生成,您需要使用 $ 传递光滑的 jdbc SQLServerProfile。

Array("slick.jdbc.SQLServerProfile", 
        "slick.jdbc.SQLServerProfile$",
        "jdbc:sqlserver://myserver.com:1433;applicationName=TestCodeGen;integratedSecurity=true;authenticationScheme=NativeAuthentication;databaseName=MYDB", 
        "src/main/scala/", 
        "com.mypackage", 
        "myUserId", 
        "")

如果这不起作用,请尝试将 jtds 驱动程序添加到您的库中,并使用 jtds 样式的 url:

"jdbc:jtds:sqlserver://myserver.com:1433;applicationName=TestCodeGen;integratedSecurity=true;authenticationScheme=NativeAuthentication;databaseName=MYDB"

您的 jtds 依赖项如下所示:

libraryDependencies += "net.sourceforge.jtds" % "jtds" % "1.3.1"
于 2017-03-23T02:41:32.297 回答