Hello iam trying to implement jpa using hibernate in eclipse kepler
here is my entity class
Code:
package com.jpa;
import java.io.Serializable;
import javax.persistence.*;
/**
* Entity implementation class for Entity: jpaexample
*
*/
@Entity
public class jpaexample {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String summary;
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
}
And my persisting class
Code:
package com.jpa;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class persistjpa {
public static void main(String[] args)
{
EntityManagerFactory factory=Persistence.createEntityManagerFactory("JpaExamples");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
jpaexample f=new jpaexample();
f.setSummary("jpa test");
em.persist(f);
em.getTransaction().commit();
em.close();
}
}
And my persistence.xml file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="JpaExamples" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.jpa.jpaexample</class>
<properties>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value="google"/>
<property name="hibernate.connection.url" value="jdbc:sqlserver://localhost:1433;databaseName=rithishdb"/>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost:1433;databaseName=rithishdb"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value="google"/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
</properties>
</persistence-unit>
</persistence>
And the following error i get like this
Code:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named JpaExamples
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.jpa.persistjpa.main(persistjpa.java:13)