Thread: javax.persistence.PersistenceException: No Persistence provider for EntityManager named automobile

Forum : Hibernate Core and Annotations.   31 Aug, 2017 10:17
User Image
Balakrishn

Newbie

Joined: 25 Jun, 2017

Points: 100

Threads: 1

Posts: 5

Answer Icon javax.persistence.PersistenceException: No Persistence provider for EntityManager named automobile

| Quote Date : 31 Aug, 2017    Views:2008    

Exception in working with Gradle + JPA+Hibernate
Folder Structure:-
FirstGradleHibernateProject
src/main/java
com.gradel.entity
Advisor.java
       com.gradel.show
GradleTest.java
src/main/resources
META-INF
persistence.xml


Advisor.java:-
package com.gradel.entity;
@Entity
@Table(name="ADVISOR")
public class Advisor
{
@Id
@Column(name="ADVISOR_NO")
@Basic(fetch=FetchType.EAGER)
protected int advisorNO;
@Column(name="FIRST_NM")
protected String firstName;
@Column(name="LAST_NM")
protected String lastName;
@Column(name="QUALIFICATION")
protected String qualification;

protected int experience;
@Column(name="CONTACT_NO")
protected String contactNumber;
@Column(name="EMAIL_ADDRESS")
protected String emailAddress;
// asume that i write toString and setters and getters also
}
GradleTest.java:-
package com.gradel.show;
public class GradleTest {
public static void main(String[] args)
{
EntityManagerFactory factory = Persistence.createEntityManagerFactory("automobile");
EntityManager manager = factory.createEntityManager();
Advisor advisor = manager.find(Advisor.class, 101);
System.out.println(advisor);
}
}

persistence.xml:-
version="2.0">
<persistence-unit name="automobile" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.gradel.entity.Advisor</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myautomobile" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>

Exception Info:-
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named automobile
at com.gradel.show.GradleTest.main(GradleTest.java:13)

Comments

User Image
Ganesh4183

Newbie

Joined : 20 Apr, 2017

Points : 100

Threads: 0

Posts: 2

Re: javax.persistence.PersistenceException: No Persistence provider for EntityManager named automobile

Reply Date : 1 Sep, 2017

working with hibernate-core-5.2.10.FINAL jar ...thanks sriman

User Image
Ganesh4183

Newbie

Joined : 20 Apr, 2017

Points : 100

Threads: 0

Posts: 2

Re: javax.persistence.PersistenceException: No Persistence provider for EntityManager named automobile

Reply Date : 1 Sep, 2017

working with hibernate-core-5.2.10.FINAL jar while working with Gradle .....Thanks Sriman!!

"Which version of the jpa jar's you are using in Gradle. use hibernate-core-5.2.10.FINAL jar version only. Otherwise you need to add hibernate-jpa jar also as dependency"

Replied by Sriman
User Image
Sriman

Member

Joined : 15 Jul, 2016

Points : 1020

Threads: 645

Posts: 207

Answer IconRe: javax.persistence.PersistenceException: No Persistence provider for EntityManager named automobile

Reply Date : 31 Aug, 2017

Which version of the jpa jar's you are using in Gradle. use hibernate-core-5.2.10.FINAL jar version only. Otherwise you need to add hibernate-jpa jar also as dependency

User Image
Balakrishn

Newbie

Joined : 25 Jun, 2017

Points : 100

Threads: 1

Posts: 5

Re: javax.persistence.PersistenceException: No Persistence provider for EntityManager named automobile

Reply Date : 31 Aug, 2017

I am working on Gradle Project with JPA and Hibernate
With out Gradle its working when I use Gradle Project only it's getting Exception

"make sure your project folder structure in this way only
project name
---src
------packages
--------classes
------META-INF
---------persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
     <persistence-unit name="automobiles" transaction-type="RESOURCE_LOCAL">
         
          <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
          <class>com.jpa.entities.Advisor</class>
          <properties>
          <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
          <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/automobiles"></property>
          <property name="javax.persistence.jdbc.user" value="root"></property>
          <property name="javax.persistence.jdbc.password" value="root"></property>
          <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property>
          <property name="hibernate.show_sql" value="true"></property>
          </properties>
     </persistence-unit>
</persistence>

?
it will work
"

Replied by chowdaka5
Load More

No More Comments