-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: javax.persistence.persistence exception
PostPosted: Fri Jun 26, 2009 1:45 am 
Newbie

Joined: Fri Jun 26, 2009 1:13 am
Posts: 1
Hi,

I was working on JPA project, i have added all the jars as well as the persistence.xml file is also saved in META-INF, but still am facing the following exception:

WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpa
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at roseindia.JPACreate.main(JPACreate.java:44)

Below are the codes for the two java class and my persistence.xml file:


Student.java

package roseindia;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.Table;

@Entity

@Table(name="student")

public class Student {

@Id

@GeneratedValue

private int id;

/**

* @return the id

*/

public int getId() {

return id;

}

/**

* @param id the id to set

*/

public void setId(int id) {

this.id = id;

}

@Column(name="sname", length=100,nullable=false)

private String sname;

/**

* @return the sname

*/

public String getSname() {

return sname;

}

/**

* @param sname the sname to set

*/

public void setSname(String sname) {

this.sname = sname;

}

@Column(name="sroll",nullable=false)

private int sroll;

/**

* @return the sroll

*/

public int getSroll() {

return sroll;

}

/**

* @param sroll the sroll to set

*/

public void setSroll(int sroll) {

this.sroll = sroll;

}

@Column(name="scourse",length=10,nullable=false)

private String scourse;

/**

* @return the scourse

*/

public String getScourse() {

return scourse;

}

/**

* @param scourse the scourse to set

*/

public void setScourse(String scourse) {

this.scourse = scourse;

}

}
JPACreate.java

/**
*
*/
package roseindia;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import roseindia.Student;

/**
* @author Administrator
*
*/
public class JPACreate {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub


EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa");
EntityManager em = emf.createEntityManager();
try{
em.getTransaction().begin();
Student st = new Student();
st.setSname("Vinod Kumar");
st.setSroll(25);
st.setScourse("MBBS");
em.persist(st);
em.getTransaction().commit();
}
catch(Exception e){
System.out.println(e.getMessage());
}
finally{
em.close();
}

}

}




Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>

<persistence>

<persistence-unit name="jpa">

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

<class>Student</class>

<properties>

<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpacrud"/>

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

<property name="hibernate.connection.password" value="root"/>

<property name="hibernate.connection.username" value="root"/>

<property name="hibernate.hbm2ddl.auto" value="update"/>

<property name="hibernate.show_sql" value="true"/>

<property name="hibernate.max_fetch_depth" value="3"></property>

<!--

<property name="hibernate.format_sql" value="true"/>

-->

</properties>

</persistence-unit>

</persistence>


Can anyone suggest a solution for this problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.