No Persistence Provider For Entitymanager Named

No Persistence provider for EntityManager named

After <persistence-unit name="agisdb">, define the persistence provider name:

<provider>org.hibernate.ejb.HibernatePersistence</provider>

No Persistence provider for EntityManager named (New)

I think the exception you posted is caused when there is no persistence unit which matches to name you passed on Persistence.createEntityManagerFactory.
In your case:

<persistence-unit name="TimeEven DataBasePU">

So, could you check your persistence.xml if you are sure that persistence unit's name is same as you wrote in the code?

Or, Posting your persistence.xml might be helpful to solve your problem.

EDIT 1:
Can you check your dependencies?

If you use maven(pom.xml), It must have:

<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.1</version>
<scope>provided</scope>
</dependency>

No Persistence provider for EntityManager named X

You must move persistence.xml file to an appropriate location.

More specifically, add META-INF/persistence.xml file to the root of a source folder.

In this case, the following is an appropriate location: src\main\java\META-INF\persistence.xml

Here are the details:
(taken from the JPA spec)

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.

The root of the persistence unit is the key here.

If you are a non-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.

If you are in a Java EE app, the following are valid

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

javax.persistence.PersistenceException: No Persistence provider for EntityManager named customerManager

Your persistence.xml is not valid and the EntityManagerFactory can't get created. It should be:

<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="customerManager" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Customer</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="1234"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/general"/>
<property name="hibernate.max_fetch_depth" value="3"/>
</properties>
</persistence-unit>
</persistence>

(Note how the <property> elements are closed, they shouldn't be nested)

Update: I went through the tutorial and you will also have to change the Id generation strategy when using MySQL (as MySQL doesn't support sequences). I suggest using the AUTO strategy (defaults to IDENTITY with MySQL). To do so, remove the SequenceGenerator annotation and change the code like this:

@Entity
@Table(name="TAB_CUSTOMER")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="CUSTOMER_ID", precision=0)
private Long customerId = null;

...
}

This should help.

PS: you should also provide a log4j.properties as suggested.



Related Topics



Leave a reply



Submit