玩 2.4 框架和 MySQL

Play 2.4 Framework and MySQL

我无法使用 MySqL 与 Play 2.4 一起工作

例如,如果我基于 "play-java-intro" 模板创建一个带有激活器的应用程序 (详见下文)对应于 video shown on the start page of playframework.com, 到目前为止一切正常。然而,这是使用内存中的 h2 数据库。

当我尝试修改项目以改为使用 mysql 时,我得到 "Execution exception":

--- (Running the application, auto-reloading is enabled) ---

[info] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] - application - Creating Pool for datasource 'default'
[info] - play.api.db.HikariCPConnectionPool - datasource [default] bound to JNDI as DefaultDS
[info] - play.api.db.DefaultDBApi - Database [default] connected at jdbc:mysql://localhost/foo_db
[info] - play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
[info] - play.api.Play - Application started (Dev)
[error] - play.core.server.netty.PlayDefaultUpstreamHandler - Cannot invoke the action
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:35)
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.class(DefaultJPAApi.java:30)
  while locating play.db.jpa.DefaultJPAApi$JPAApiProvider
  while locating play.db.jpa.JPAApi

1 error
        at com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1025) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051) ~[guice.jar:na]
        at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.inject.DelegateInjector.instanceOf(DelegateInjector.java:22) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.JPA.jpaApi(JPA.java:46) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.JPA.withTransaction(JPA.java:159) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.TransactionalAction.call(TransactionalAction.java:16) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:94) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:94) ~[play_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) ~[scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.10.5.jar:na]
        at play.core.j.HttpExecutionContext$$anon.run(HttpExecutionContext.scala:40) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:32) ~[play_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.impl.Future$.apply(Future.scala:31) ~[scala-library-2.10.5.jar:na]
        at scala.concurrent.Future$.apply(Future.scala:485) ~[scala-library-2.10.5.jar:na]
        at play.core.j.JavaAction.apply(JavaAction.scala:94) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply$$anonfun$apply.apply(Action.scala:105) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply$$anonfun$apply.apply(Action.scala:105) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply.apply(Action.scala:104) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply.apply(Action.scala:103) ~[play_2.10-2.4.2.jar:2.4.2]
        at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
        at play.api.mvc.Action$$anonfun$apply.apply(Action.scala:103) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply.apply(Action.scala:96) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$mapM.apply(Iteratee.scala:524) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$mapM.apply(Iteratee.scala:524) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM.apply(Iteratee.scala:560) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM.apply(Iteratee.scala:560) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$$anonfun$apply.apply(Iteratee.scala:537) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$$anonfun$apply.apply(Iteratee.scala:537) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) ~[scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.10.5.jar:na]
        at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) [akka-actor_2.10-2.3.11.jar:na]
        at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) [akka-actor_2.10-2.3.11.jar:na]
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.5.jar:na]
Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
        at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.perform(EntityManagerFactoryBuilderImpl.java:852) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.perform(EntityManagerFactoryBuilderImpl.java:845) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83) ~[persistence-api-1.0.jar:1.0]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) ~[persistence-api-1.0.jar:1.0]
        at play.db.jpa.DefaultJPAApi.start(DefaultJPAApi.java:56) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:42) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.DefaultJPAApi$JPAApiProvider$$FastClassByGuice$$dcd4cdbd.newInstance(<generated>) ~[guice.jar:2.4.2]
        at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40) ~[guice.jar:na]
        at com.google.inject.internal.DefaultConstructionProxyFactory.newInstance(DefaultConstructionProxyFactory.java:61) ~[guice.jar:na]
        at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105) ~[guice.jar:na]
        at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85) ~[guice.jar:na]
        at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267) ~[guice.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter.call(ProviderToInternalFactoryAdapter.java:46) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) ~[guice.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) ~[guice.jar:na]
        at com.google.inject.internal.SingletonScope.get(SingletonScope.java:145) ~[guice.jar:na]
        at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) ~[guice.jar:na]
        at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.call(InjectorImpl.java:1016) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1012) ~[guice.jar:na]
        ... 38 common frames omitted
[error] - application - 

! @6n9po3p32 - Internal server error, for (POST) [/person] ->

play.api.http.HttpErrorHandlerExceptions$$anon: Execution exception[[ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:35)
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.class(DefaultJPAApi.java:30)
  while locating play.db.jpa.DefaultJPAApi$JPAApiProvider
  while locating play.db.jpa.JPAApi

1 error]]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:265) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.GlobalSettings$class.onError(GlobalSettings.scala:179) [play_2.10-2.4.2.jar:2.4.2]
        at play.api.DefaultGlobal$.onError(GlobalSettings.scala:212) [play_2.10-2.4.2.jar:2.4.2]
        at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:94) [play_2.10-2.4.2.jar:2.4.2]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun.applyOrElse(PlayDefaultUpstreamHandler.scala:273) [play-netty-server_2.10-2.4.2.jar:2.4.2]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun.applyOrElse(PlayDefaultUpstreamHandler.scala:269) [play-netty-server_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:344) [scala-library-2.10.5.jar:na]
        at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:343) [scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.5.jar:na]
        at play.api.libs.iteratee.Execution$trampoline$.executeScheduled(Execution.scala:109) [play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:71) [play-iteratees_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [scala-library-2.10.5.jar:na]
        at scala.concurrent.Promise$class.complete(Promise.scala:55) [scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23) [scala-library-2.10.5.jar:na]
        at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) [akka-actor_2.10-2.3.11.jar:na]
        at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) [akka-actor_2.10-2.3.11.jar:na]
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.5.jar:na]
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.5.jar:na]
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:35)
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.class(DefaultJPAApi.java:30)
  while locating play.db.jpa.DefaultJPAApi$JPAApiProvider
  while locating play.db.jpa.JPAApi

1 error
        at com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1025) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051) ~[guice.jar:na]
        at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.inject.DelegateInjector.instanceOf(DelegateInjector.java:22) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.JPA.jpaApi(JPA.java:46) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.JPA.withTransaction(JPA.java:159) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.TransactionalAction.call(TransactionalAction.java:16) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:94) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:94) ~[play_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) [scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [scala-library-2.10.5.jar:na]
        at play.core.j.HttpExecutionContext$$anon.run(HttpExecutionContext.scala:40) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70) [play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:32) ~[play_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.impl.Future$.apply(Future.scala:31) ~[scala-library-2.10.5.jar:na]
        at scala.concurrent.Future$.apply(Future.scala:485) ~[scala-library-2.10.5.jar:na]
        at play.core.j.JavaAction.apply(JavaAction.scala:94) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply$$anonfun$apply.apply(Action.scala:105) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply$$anonfun$apply.apply(Action.scala:105) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply.apply(Action.scala:104) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply$$anonfun$apply.apply(Action.scala:103) ~[play_2.10-2.4.2.jar:2.4.2]
        at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
        at play.api.mvc.Action$$anonfun$apply.apply(Action.scala:103) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.mvc.Action$$anonfun$apply.apply(Action.scala:96) ~[play_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$mapM.apply(Iteratee.scala:524) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$mapM.apply(Iteratee.scala:524) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM.apply(Iteratee.scala:560) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM.apply(Iteratee.scala:560) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$$anonfun$apply.apply(Iteratee.scala:537) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$$anonfun$apply.apply(Iteratee.scala:537) ~[play-iteratees_2.10-2.4.2.jar:2.4.2]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) [scala-library-2.10.5.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [scala-library-2.10.5.jar:na]
        ... 6 common frames omitted
Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
        at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.perform(EntityManagerFactoryBuilderImpl.java:852) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.perform(EntityManagerFactoryBuilderImpl.java:845) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83) ~[persistence-api-1.0.jar:1.0]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) ~[persistence-api-1.0.jar:1.0]
        at play.db.jpa.DefaultJPAApi.start(DefaultJPAApi.java:56) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:42) ~[play-java-jpa_2.10-2.4.2.jar:2.4.2]
        at play.db.jpa.DefaultJPAApi$JPAApiProvider$$FastClassByGuice$$dcd4cdbd.newInstance(<generated>) ~[guice.jar:2.4.2]
        at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40) ~[guice.jar:na]
        at com.google.inject.internal.DefaultConstructionProxyFactory.newInstance(DefaultConstructionProxyFactory.java:61) ~[guice.jar:na]
        at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105) ~[guice.jar:na]
        at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85) ~[guice.jar:na]
        at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267) ~[guice.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter.call(ProviderToInternalFactoryAdapter.java:46) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) ~[guice.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) ~[guice.jar:na]
        at com.google.inject.internal.SingletonScope.get(SingletonScope.java:145) ~[guice.jar:na]
        at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) ~[guice.jar:na]
        at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.call(InjectorImpl.java:1016) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) ~[guice.jar:na]
        at com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1012) ~[guice.jar:na]
        ... 38 common frames omitted

当我尝试保存到数据库时。

"conf/evolutions/default/1.sql" 确实创建了,并且 mysql 数据库似乎确实得到了适当的 table 已插入,但我似乎无法将任何行保存到 table。

非常感谢您提供解决方案。

非常感谢。

下面是我的代码:

(1) 我有一个系统
OpenSuse 13.2 Linux,带有 Mariadb, 智能 14, 播放 2.4.2


mysql 是 运行 并且有一个数据库 "foo_db" 密码为空的用户 "root" 具有完全访问权限。

MariaDB [foo_db]> describe person_tb;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | varchar(255) | NO   | PRI | NULL    |       |
| name  | varchar(255) | YES  |     | NULL    |       |

根据"play-java-intro" 模板创建一个新的播放应用程序

> activator new play-java-intro_mysql play-java-intro
> cd my-play-java-sql
> activator run

将浏览器指向 http://localhost:9000/

该应用程序运行良好..可以按照教程中的说明添加 "persons" 等。 video tutorial

(2) 现在我修改了一些文件以尝试使用 mysql 代替。

之后的文件下方

Person.java:

package models;

import javax.persistence.*;

@Entity
@Table(name = "person_tb")
public class Person {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public String id;

    public String name;

}

appplication.conf:

play.crypto.secret = "changeme"

play.i18n.langs = [ "en" ]

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/foo_db"
db.default.username=root
db.default.password=""

ebean.default=["models.*"]
#applyEvolutions.default=true
db.default.jndiName=DefaultDS

jpa.default=defaultPersistenceUnit

build.sbt:

name := """play-java-intro_mysql"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)

libraryDependencies ++= Seq(
  evolutions,
 javaJpa,
javaJdbc,
  "mysql" % "mysql-connector-java" % "5.1.18",
  "org.hibernate" % "hibernate-entitymanager" % "4.3.7.Final"
)

routesGenerator := InjectedRoutesGenerator

plugins.sbt:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")


addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")

"activator new" 使用 "play-java-intro" 模板生成的代码不起作用(使用 MySQL)。为了让它工作,必须如下修改以下文件:

app/controllers/Application.java

package controllers;
import play.*;
import play.db.ebean.Transactional;
import play.mvc.*;
import views.html.*;
import models.Person;
import play.data.Form;
import java.util.List;
import static play.libs.Json.*;


public class Application extends Controller {

public Result index() {
    return ok(index.render());
}
@Transactional
public Result addPerson() {
    // Person person = Form.form(Person.class).bindFromRequest().get();
    // JPA.em().persist(person);
    Person person = Form.form(Person.class).bindFromRequest().get();
    person.save();
    return redirect(routes.Application.index());
}
@Transactional
public Result getPersons() {
  List<Person> persons  = Person.FIND.findList();
    //List<Person> persons = (List<Person>) JPA.em().createQuery("select p from Person p").getResultList();
    return ok(toJson(persons));
}

}

app/models/Person.java

package models;
import javax.persistence.*;
import com.avaje.ebean.Model;
@Entity
public class Person extends Model {
    @Id
    public Long id;

    public String name;
    public static Model.Finder<Long, Person> FIND = new Model.Finder<>(Person.class);
}

build.sbt

name := """play-java-intro_mysql"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
libraryDependencies ++= Seq(
   evolutions,
   javaJdbc,
   javaJpa,
  "mysql" % "mysql-connector-java" % "5.1.18"
)

routesGenerator := InjectedRoutesGenerator

project/plugins.sbt

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

// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")

// 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
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")

conf/application.conf

play.crypto.secret = "changeme"

# The application languages
play.i18n.langs = [ "en" ]

# Database configuration

#H2
#db.default.driver=org.h2.Driver
#db.default.url="jdbc:h2:mem:play"
# db.default.username=sa
# db.default.password=""

# MySQL
db.default.driver=com.mysql.jdbc.Driver

# edit as appropriate.. database called "foo_db" must exit and be accessible by this user, with this password
db.default.url="jdbc:mysql://localhost/foo_db"  
db.default.username=root 
db.default.password=""   

ebean.default=["models.*"]

命令行

   > cd play-java-intro_mysql
   > activator clean compile run