Java 在Play框架中启用JPA元模型自动生成

Java 在Play框架中启用JPA元模型自动生成,java,hibernate,jpa,playframework,playframework-2.3,Java,Hibernate,Jpa,Playframework,Playframework 2.3,更新 我正在尝试在play 2.3.0应用程序中启用JPA元模型自动生成。使用文档 我正在更改build.sbt文件,如下所示: ... libraryDependencies ++= Seq( javaCore, cache, "org.springframework" % "spring-context" % "4.0.4.RELEASE", "org.springframework" % "spring-orm" % "4.0

更新

我正在尝试在play 2.3.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
director,因为生成的文件中的包名不正确,您的程序将无法运行! 因此,您的
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")
    ...