在Play Framework中启用JPA元模型自动生成



更新!

我正在尝试在我的play 2.3.0应用程序中启用JPA元模型自动生成。在Play 2.0文档中使用类型安全的JPA查询

我正在更改我的build.sbt文件如下:

    ...
    libraryDependencies ++= Seq(
      javaCore,
      cache,
      "org.springframework" % "spring-context" % "4.0.4.RELEASE",
      "org.springframework" % "spring-orm" % "4.0.4.RELEASE",
      "org.springframework" % "spring-jdbc" % "4.0.4.RELEASE",
      "org.springframework" % "spring-tx" % "4.0.4.RELEASE",
      "org.springframework" % "spring-expression" % "4.0.4.RELEASE",
      "org.springframework" % "spring-aop" % "4.0.4.RELEASE",
      "org.springframework" % "spring-test" % "4.0.4.RELEASE" % "test",
      "org.hibernate" % "hibernate-entitymanager" % "4.3.5.Final",
      "org.hibernate" % "hibernate-jpamodelgen" % "4.3.5.Final",
      "cglib" % "cglib" % "2.2.2"
    )
    javacOptions ++= Seq("-s", "metamodel")
    ...

而我正面临这个错误:

Unexpected exception
The compilation failed without reporting any problem!
No source available, here is the exception stack trace:
->sbt.compiler.CompileFailed: 
     sbt.compiler.JavaCompiler$JavaTool0.compile(JavaCompiler.scala:77)
     sbt.compiler.JavaTool$class.apply(JavaCompiler.scala:35)
     sbt.compiler.JavaCompiler$JavaTool0.apply(JavaCompiler.scala:63)
     sbt.compiler.JavaCompiler$class.compile(JavaCompiler.scala:21)
     sbt.compiler.JavaCompiler$JavaTool0.compile(JavaCompiler.scala:63)
     sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$1.apply$mcV$sp(AggressiveCompile.scala:127)
     sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$1.apply(AggressiveCompile.scala:127)
     sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$1.apply(AggressiveCompile.scala:127)
     sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:166)
     sbt.compiler.AggressiveCompile$$anonfun$3.compileJava$1(AggressiveCompile.scala:126)
     sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:143)
     sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:87)
     sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:39)
     sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:37)
     sbt.inc.IncrementalCommon.cycle(Incremental.scala:99)
     sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:38)
     sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:37)
     sbt.inc.Incremental$.manageClassfiles(Incremental.scala:65)
     sbt.inc.Incremental$.compile(Incremental.scala:37)
     sbt.inc.IncrementalCompile$.apply(Compile.scala:27)
     sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:157)
     sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:71)
     sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:46)
     sbt.Compiler$.apply(Compiler.scala:75)
     sbt.Compiler$.apply(Compiler.scala:66)
     sbt.Defaults$.sbt$Defaults$$compileTaskImpl(Defaults.scala:770)
     sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:762)
     sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:762)
     scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
     sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
     sbt.std.Transform$$anon$4.work(System.scala:64)
     sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
     sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
     sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
     sbt.Execute.work(Execute.scala:244)
     sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
     sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
     sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
     sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
     java.util.concurrent.FutureTask.run(Unknown Source)
     java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
     java.util.concurrent.FutureTask.run(Unknown Source)
     java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
     java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
     java.lang.Thread.run(Unknown Source)

好!我的问题解决了!

javacOptions中,您应该为自动生成的元数据寻址现有文件夹。意味着app/everyWhere,但在hibernate中存在一个问题,即它无法覆盖包名称,并且如果您寻址任何其他位置的app控制器,由于生成的文件中的包名称不正确,您的程序将无法运行!所以你的build.sbt是这样的:

...
    libraryDependencies ++= Seq(
      javaCore,
      cache,
      "org.springframework" % "spring-context" % "4.0.4.RELEASE",
      "org.springframework" % "spring-orm" % "4.0.4.RELEASE",
      "org.springframework" % "spring-jdbc" % "4.0.4.RELEASE",
      "org.springframework" % "spring-tx" % "4.0.4.RELEASE",
      "org.springframework" % "spring-expression" % "4.0.4.RELEASE",
      "org.springframework" % "spring-aop" % "4.0.4.RELEASE",
      "org.springframework" % "spring-test" % "4.0.4.RELEASE" % "test",
      "org.hibernate" % "hibernate-entitymanager" % "4.3.5.Final",
      "org.hibernate" % "hibernate-jpamodelgen" % "4.3.5.Final",
      "cglib" % "cglib" % "2.2.2"
    )
    javacOptions ++= Seq("-s", "app")
    ...

最新更新