2011-12-05 250 views
0

我有这个项目,我使用hibernate,JPA,Tomcat和JSF。 无论如何,我一直试图解决这个错误超过两个小时没有成功。 我所有的罐子都包括在内,但这个错误不想给我一个喙。 这是我的错误:没有EntityManager的持久性提供者

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named examplePersistenceUnit 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34) 
    at test.TestBase.<init>(TestBase.java:15) 
    at test.TestCandidat.<init>(TestCandidat.java:14) 
    at test.TestCandidat.main(TestCandidat.java:83) 

这是我的persistence.xml:

<?xml version="1.0" 

encoding="UTF-8"?> 
<persistence> 
    <persistence-unit name="examplePersistenceUnit" 
     transaction-type="RESOURCE_LOCAL"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <properties> 
      <property name="hibernate.show_sql" value="false" /> 
      <property name="hibernate.format_sql" value="false" /> 

      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> 
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/RecrutementDB" /> 
      <property name="hibernate.connection.username" value="root" /> 
      <property name="hibernate.connection.password" value="3031989" /> 

      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 
      <property name="hibernate.hbm2ddl.auto" value="create" /> 
     </properties> 
    </persistence-unit> 
</persistence> 
+0

有一件事我不会,我会非常有帮助,我有这个警告在我的persistence.xml“没有语法约束(DTD或XML模式)为文档检测到。“ – Amson

+0

http://stackoverflow.com/questions/3739387/javax-persistence-persistenceexception-no-persistence-provider-for-entitymanage - 这可能有帮助吗?特别是名称空间声明。 – Paul

+0

红外线帮助不知何故,我设法通过添加propertie文件fiwj lo4j警告,所以我可以找到我的问题感谢回答 – Amson

回答

0

首先添加WEB-INF下log4j.properties文件,并在META-INF文件夹中。如果确定的persistence.xml不帮助你可能在persistence.xml中有一个语法错误

相关问题