My persistence xml file is like that
<?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>
Then I have my code calling it with this:
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();
}
}
I got the following error message:
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)