2015-04-02 65 views
0

我一直在努力工作这一个了几天,但没有我尝试过的许多事情工作!是什么导致这个“没有持久性提供者的EntityManager名为___”异常?

javax.persistence.PersistenceException:没有名为用户 的EntityManager

我已经看到了发生冲突的确切位置的persistence.xml应位于报告持久性提供者 - 要么是地方我有以下正确?

显然这个错误的原因可能是我有persistence.xml在错误的地方(我不认为我这样做),持久性提供程序jar不在类路径(我认为是),或者说我的依赖关系是不对的(我猜是这样,但不能告诉!)

Location of my persistnece.xml 内容的persistence.xml的:

<?xml version="1.0" encoding="UTF-8"?> 

<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_1_0.xsd" version="1.0"> 

<persistence-unit name="user"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 

    <class>main.java.Account.User</class> 

    <properties> 
     <property name="javax.persistence.jdbc.user" value="root" /> 
     <property name="hibernate.show_sql" value="true" /> 
     <property name="hibernate.hbm2ddl.auto" value="update" /> 
     <property name="javax.persistence.jdbc.url" value="jdbc:google:mysql://grade-me:datastore/grademe?user=root"/> 
     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5"/> 
    </properties> 

</persistence-unit> 

级构建文件:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.google.appengine:gradle-appengine-plugin:1.9.14' 
    } 
} 

repositories { 
    jcenter(); 
} 

apply plugin: 'java' 
apply plugin: 'war' 
apply plugin: 'appengine' 

sourceCompatibility = JavaVersion.VERSION_1_7 
targetCompatibility = JavaVersion.VERSION_1_7 

dependencies { 
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.14' 

    compile fileTree(dir: 'libs', include: ['*.jar']) 

    compile 'com.google.appengine:appengine-endpoints:1.9.14' 
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.14' 
    compile 'javax.servlet:servlet-api:2.5' 
    compile 'org.hibernate:hibernate-core:4.3.8.Final' 
} 

appengine { 
    downloadSdk = true 
    appcfg { 
     oauth2 = true 
    } 
    endpoints { 
     getClientLibsOnBuild = true 
     getDiscoveryDocsOnBuild = true 
    } 
} 

我将是任何帮助难以置信感谢(请去容易对我,如果这是愚蠢的东西!)谢谢

编辑:只是想我会更新到任何人碰到这个,不幸的是我没有绊脚石设法使用任何这些建议来让休眠工作,并选择使用Objectify来代替。

+0

您的'persistence.xml'位置正确。你在使用实体经理吗?你在哪里以及如何初始化它? – wypieprz 2015-04-02 17:06:19

+0

谢谢。我使用 “EntityManagerFactory emf = Persistence.createEntityManagerFactory(”user“); EntityManager entityManager = emf.createEntityManager();”我使用 中的类中的方法初始化它。 – Eden 2015-04-02 17:14:26

+0

对我来说很好。 – wypieprz 2015-04-02 17:17:24

回答

1

尝试将hibernate-entitymanager更改为类似于hibernate-core的编译依赖项。这可能是fileTree依赖关系的问题。

相关问题