2013-09-16 4 views
2

Мой файл XML настойчивость как топровайдер Нет Постоянство для EntityManager с именем ... Ошибка

<?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="hibernateEbru">  
     <provider>org.hibernate.ejb.HibernatePersistence</provider>  
     <class>com.hibernate.business_card</class> 
     <properties>    
      <property name="hibernate.hbm2ddl.auto" value="create" />   
      <property name="hibernate.show_sql" value="true" />   
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />   
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />   
      <property name="hibernate.connection.username" value="root" />   
      <property name="hibernate.connection.password" value="2643" />   
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/BusinessDb" /> 

     </properties> 
    </persistence-unit> 
</persistence> 

Тогда я мой код, назвав его с этим:

public class test { 
    public static void main(String[] args) { 
     EntityManagerFactory emf = Persistence.createEntityManagerFactory("hibernateEbru"); 

     EntityManager em = emf.createEntityManager(); 

     em.getTransaction().begin(); 

     business_card bc = new business_card(); 
     bc.setName("Ebru"); 

     em.persist(bc); 

     em.getTransaction().commit(); 

     em.close(); 

     emf.close(); 

    } 
} 

я получил следующее сообщение об ошибке :

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named hibernateEbru 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34) 
    at com.hibernate.test.main(test.java:8) 
+0

и я addes эти банки; proxool-0.8.3 OSCache-2.1 MySQL-разъем log4j JTA-1,1- jbosscache ядро-3.2.2-GA javassist-3.12.0.GA infinispan-ядро-4.2.1.CR1 hibernate- тестирование hibernate-jpa-2.0-api-1.0.1.Final Hibernate-Обще-аннотаций Hibernate-аннотаций hibernate3 ejb3-инерционности dom4j-1.6.1 Викисклада коллекции-3.1 CGLIB-2,2 c3p0- 0.9.1 antlr-2.7.6 hibernate -entitymanager-4.0.1.Final slf4j-api-1.6.6 slf4j-log4j12-1.6.6 – ebruszl

+2

Обычно это происходит потому, что persistence.xml находится не в нужном месте. Можете ли вы предоставить, где это живет в вашем проекте? – cmd

ответ

0

Вам нужно будет переместить файл persistence.xml в соответствующем месте

От JPA спецификации:

A persistence.xml file defines a persistence unit. The persistence.xml file is 
located in the META-INF directory of the root of the persistence unit. 

Корень единицы сохранения является ключевым здесь.

Если вы не-Java EE App

The jar file or directory whose META-INF directory contains the persistence.xml 
file is termed the root of the persistence unit. 

Если вы находитесь в приложении Java EE, допустимы следующие

In Java EE environments, the root of a persistence unit must be one of the following: 
• an EJB-JAR file 
• the WEB-INF/classes directory of a WAR file[80] 
• a jar file in the WEB-INF/lib directory of a WAR file 
• a jar file in the EAR library directory 
• an application client jar file 
Смежные вопросы