没有EntityManager的持久性提供程序

时间:2011-12-05 21:43:18

标签: hibernate jpa

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

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>

1 个答案:

答案 0 :(得分:0)

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