【问题标题】:Play Framework Error: play.sbt.PlayExceptions播放框架错误:play.sbt.PlayExceptions
【发布时间】:2017-10-03 17:19:16
【问题描述】:

我是游戏框架的新手。我有一个项目,但它给我带来了问题。

我使用 Play Framework 2.5.9 和 ebean 3.0.2。错误如下:

play.sbt.PlayExceptions$CompilationException: Compilation error[value where is not a member of com.avaje.ebean.Finder[Long,models.Viaje]]
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
    at scala.Option.map(Option.scala:145)
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49)
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
    at scala.Option.map(Option.scala:145)
    at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44)
    at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40)
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)

生成的错误也与模型类有关。在每个类中,我都定义了以下方法:

public static Finder<Long, Motorista> find = new Finder<Long,Motorista>(Motorista.class);

我按照以下命名法进行任何查询:

Motorista.find.findList (); 

或:

Motorista.find.where (). eq ( "id", 1);

问题是,在我进行这些查询的所有行中,上述错误总是后面跟着错误,错误说:

value findList is not a member of com.avaje.ebean.Finder [Long, models.Motorista] 

value where is not a member of com.avaje.ebean.Finder [Long, models.Motorista]

我认为这可能是一个配置问题,尽管该项目对我来说运行良好。

我的 build.sbt 文件包含以下内容

名称 := """siiaf"""

版本 := "1.0-SNAPSHOT"

lazy val myProject = (project in file(".")).enablePlugins(PlayJava, PlayEbean)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs
)
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"

我的 plugins.sbt 文件包含以下内容:

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.9")

// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.8")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.6")

// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(PlayEbean).
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.2")

请帮忙

【问题讨论】:

    标签: java scala playframework


    【解决方案1】:

    问题在于他在 Scala 视图中进行查询,例如:

    ModelClass.find.where().eq ("id", 1).findList()
    

    根据 play framework 2.5.x 的文档,这是不可能的:

    https://www.playframework.com/documentation/2.5.x/JavaEbean

    Play 旨在自动生成 getter/setter,以 确保与期望它们可用的库的兼容性 在运行时(ORM、Databinder、JSON Binder 等)。如果 Play 检测到任何 模型中用户编写的getter/setter,它不会生成 getter/setter 以避免任何冲突。

    注意事项:

    (1) 因为 Ebean 类增强是在编译后发生的,所以不要 期望 Ebean 生成的 getter/setter 在编译时可用 时间。如果您希望直接使用它们编写代码,请添加 getter/setter 你自己明确地,或者确保你的模型类 在项目的其余部分之前编译,例如。通过把它们 在一个单独的子项目中。

    (2) 增强直接 Ebean 字段访问(启用延迟加载) 仅适用于 Java 类,不适用于 Scala。因此,直接场 从 Scala 源文件(包括标准 Play 模板)访问 不调用延迟加载,通常会导致空(未填充) 实体字段。为确保字段被填充,要么 (a) 手动 创建 getter/setter 并改为调用它们,或者 (b) 确保实体 在访问字段之前已完全填充。

    解决方案是在模板中包含以下内容:

    @import com.avaje.ebean.Ebean
    

    并在模板中进行这样的查询:

    Ebean.find(classOf[ModelClass]).where().eq("id",1).findList()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2016-02-16
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多