Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Play framework 2.0 JPA Mysql错误:无法构建EntityManagerFactory_Mysql_Hibernate_Jpa_Playframework - Fatal编程技术网

Play framework 2.0 JPA Mysql错误:无法构建EntityManagerFactory

Play framework 2.0 JPA Mysql错误:无法构建EntityManagerFactory,mysql,hibernate,jpa,playframework,Mysql,Hibernate,Jpa,Playframework,我试图使用PlayFramework2.0构建一个Java项目。我尝试在游戏中配置JPA,如下所示: conf/application.conf conf/META-INF/persistence.xml app/models/user.java app/controllers/application.java 然后,在工作目录中键入play,然后在控制台中键入run,堆栈中的错误如下: [info] play - datasource [jdbc:mysql://localhost:3306/

我试图使用PlayFramework2.0构建一个Java项目。我尝试在游戏中配置JPA,如下所示:

conf/application.conf

conf/META-INF/persistence.xml

app/models/user.java

app/controllers/application.java

然后,在工作目录中键入play,然后在控制台中键入run,堆栈中的错误如下:

[info] play - datasource [jdbc:mysql://localhost:3306/tt] bound to JNDI as Defau
ltDS
[info] play - database [default] connected at jdbc:mysql://localhost:3306/tt
[error] application -

! @6akap0ohi - Internal server error, for request [GET /] ->

play.api.UnexpectedException: Unexpected exception [PersistenceException: [Persi
stenceUnit: defaultPersistenceUnit] Unable to build EntityManagerFactory]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anon
fun$1.apply(ApplicationProvider.scala:134) ~[play_2.9.1.jar:2.0]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anon
fun$1.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0]
        at scala.Option.map(Option.scala:133) ~[scala-library.jar:0.11.2]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply
(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply
(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0]
        at scala.Either$RightProjection.flatMap(Either.scala:277) ~[scala-librar
y.jar:0.11.2]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: defaultPers
istenceUnit] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con
figuration.java:915) ~[hibernate-entitymanager-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con
figuration.java:890) ~[hibernate-entitymanager-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(Hib
ernatePersistence.java:57) ~[hibernate-entitymanager-4.1.2.Final.jar:4.1.2.Final
]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:63) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:47) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
        at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:35) ~[play_2.9.1.jar:2.0
]
Caused by: org.hibernate.HibernateException: Dialect class not found: org.hibern
ate.dialect.MYSQL5Dialect
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constr
uctDialect(DialectFactoryImpl.java:76) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildD
ialect(DialectFactoryImpl.java:64) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]

        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer
vicesImpl.java:146) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.service.internal.StandardServiceRegistryImpl.configureS
ervice(StandardServiceRegistryImpl.java:75) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize
Service(AbstractServiceRegistryImpl.java:159) ~[hibernate-core-4.1.2.Final.jar:4
.1.2.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService
(AbstractServiceRegistryImpl.java:131) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable
to load class [org.hibernate.dialect.MYSQL5Dialect]
        at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.cl
assForName(ClassLoaderServiceImpl.java:141) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constr
uctDialect(DialectFactoryImpl.java:73) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildD
ialect(DialectFactoryImpl.java:64) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]

        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer
vicesImpl.java:146) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.service.internal.StandardServiceRegistryImpl.configureS
ervice(StandardServiceRegistryImpl.java:75) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize
Service(AbstractServiceRegistryImpl.java:159) ~[hibernate-core-4.1.2.Final.jar:4
.1.2.Final]
Caused by: java.lang.ClassNotFoundException: Could not load requested class : or
g.hibernate.dialect.MYSQL5Dialect
        at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.
findClass(ClassLoaderServiceImpl.java:99) ~[hibernate-core-4.1.2.Final.jar:4.1.2
.Final]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307) ~[na:1.6.0_23]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ~[na:1.6.0_23]
        at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.cl
assForName(ClassLoaderServiceImpl.java:138) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constr
uctDialect(DialectFactoryImpl.java:73) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildD
ialect(DialectFactoryImpl.java:64) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]

尝试在META-INF\persistence.xml中将字符串:DefaultDS修改为DefaultDS

尝试在META-INF\persistence.xml中将字符串:DefaultDS修改为DefaultDS

在例外情况下,其显示缺少的类是org.hibernate.dialen.mysql5dialent&您在persistence.xml中提到了org.hibernate.dialen.mysqldialent.mysqldialent,所以试着改变它。我已经试过了:我把persistence.xml中的org.hibernate.dialogue.mysqldialogue改为org.hibernate.dialogue.mysql5dialogue。但是,错误是相同的~确保jar位于classpath中,并尝试在jar中查找方言类。除了显示缺少的类是org.hibernate.dialogue.mysql5dialogue之外&您在persistence.xml中提到了org.hibernate.dialogue.mysqldialogue,所以试着改变它。我已经试过了:我把persistence.xml中的org.hibernate.dialogue.mysqldialogue改为org.hibernate.dialogue.mysql5dialogue。但是,错误是相同的~确保jar在classpath中&尝试在jar中查找方言类。
<persistence xmlns="http://java.sun.com/xml/ns/persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/ persistence
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0"> <persistence-unit name="defaultPersistenceUnit"
     transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>DefaultDS</non-jta-data-source>  <properties> 
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> 
    <property name="hibernate.hbm2ddl.auto" value="update"/> 
    </properties>
     </persistence-unit>  
     </persistence>
import sbt._ 
import Keys._
import PlayProject._
 object ApplicationBuild extends Build {
    val appName         = "appjava"
    val appVersion      = "1.0"
    val appDependencies = Seq(
     // Add your project dependencies here,
     "mysql" % "mysql-connector-java" % "5.1.19",
     "org.hibernate" % "hibernate-entitymanager" % "4.1.2.Final"
     )
    val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
     // Add your own project settings here      
     )
    }
package models;
import javax.persistence.*;
import play.data.validation.Constraints.Required;
import play.db.jpa.JPA;
@Entity
 public class user {
        @Id
        public Long id;
        @Required
        public String name;
        public static user findById(Long id) {
           return JPA.em().find(user.class, id);
        }
 }
package controllers;
import models.*;
import play.*;
import play.db.jpa.Transactional;
import play.mvc.*;
import views.html.*;
 public class Application extends Controller {
     @Transactional
     public static Result index() {
           user u = user.findById((long)1);
          return ok(index.render(u.name));
     }

    }
[info] play - datasource [jdbc:mysql://localhost:3306/tt] bound to JNDI as Defau
ltDS
[info] play - database [default] connected at jdbc:mysql://localhost:3306/tt
[error] application -

! @6akap0ohi - Internal server error, for request [GET /] ->

play.api.UnexpectedException: Unexpected exception [PersistenceException: [Persi
stenceUnit: defaultPersistenceUnit] Unable to build EntityManagerFactory]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anon
fun$1.apply(ApplicationProvider.scala:134) ~[play_2.9.1.jar:2.0]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anon
fun$1.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0]
        at scala.Option.map(Option.scala:133) ~[scala-library.jar:0.11.2]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply
(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply
(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0]
        at scala.Either$RightProjection.flatMap(Either.scala:277) ~[scala-librar
y.jar:0.11.2]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: defaultPers
istenceUnit] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con
figuration.java:915) ~[hibernate-entitymanager-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con
figuration.java:890) ~[hibernate-entitymanager-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(Hib
ernatePersistence.java:57) ~[hibernate-entitymanager-4.1.2.Final.jar:4.1.2.Final
]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:63) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:47) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
        at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:35) ~[play_2.9.1.jar:2.0
]
Caused by: org.hibernate.HibernateException: Dialect class not found: org.hibern
ate.dialect.MYSQL5Dialect
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constr
uctDialect(DialectFactoryImpl.java:76) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildD
ialect(DialectFactoryImpl.java:64) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]

        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer
vicesImpl.java:146) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.service.internal.StandardServiceRegistryImpl.configureS
ervice(StandardServiceRegistryImpl.java:75) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize
Service(AbstractServiceRegistryImpl.java:159) ~[hibernate-core-4.1.2.Final.jar:4
.1.2.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService
(AbstractServiceRegistryImpl.java:131) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable
to load class [org.hibernate.dialect.MYSQL5Dialect]
        at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.cl
assForName(ClassLoaderServiceImpl.java:141) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constr
uctDialect(DialectFactoryImpl.java:73) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildD
ialect(DialectFactoryImpl.java:64) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]

        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer
vicesImpl.java:146) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]
        at org.hibernate.service.internal.StandardServiceRegistryImpl.configureS
ervice(StandardServiceRegistryImpl.java:75) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize
Service(AbstractServiceRegistryImpl.java:159) ~[hibernate-core-4.1.2.Final.jar:4
.1.2.Final]
Caused by: java.lang.ClassNotFoundException: Could not load requested class : or
g.hibernate.dialect.MYSQL5Dialect
        at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.
findClass(ClassLoaderServiceImpl.java:99) ~[hibernate-core-4.1.2.Final.jar:4.1.2
.Final]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307) ~[na:1.6.0_23]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ~[na:1.6.0_23]
        at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.cl
assForName(ClassLoaderServiceImpl.java:138) ~[hibernate-core-4.1.2.Final.jar:4.1
.2.Final]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constr
uctDialect(DialectFactoryImpl.java:73) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Fi
nal]
        at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildD
ialect(DialectFactoryImpl.java:64) ~[hibernate-core-4.1.2.Final.jar:4.1.2.Final]