Im trying to figure out this entity manager thing. So please bare with me. Why am I getting this error, the JDBC driver I use is in the classpath of my eclipse.
Code:
SEVERE: JDBC Driver class not found:
java.lang.ClassNotFoundException:
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:109)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1502)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:472)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:385)
at org.hibernate.ejb.HibernatePersistence.createFactory(HibernatePersistence.java:152)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:199)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
at co.za.easypay.reportconfig.GetTest.main(GetTest.java:13)
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: JDBC Driver class not found:
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:206)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
at co.za.easypay.reportconfig.GetTest.main(GetTest.java:13)
Caused by: org.hibernate.HibernateException: JDBC Driver class not found:
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1502)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:472)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:385)
at org.hibernate.ejb.HibernatePersistence.createFactory(HibernatePersistence.java:152)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:199)
... 3 more
Caused by: java.lang.ClassNotFoundException:
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:109)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 13 more
persistence.xml
Code:
<entity-manager>
<name>manager1</name>
<class>co.za.easypay.reportconfig.Person</class>
<properties>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">false</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://196.34.50.153:3306/bps_hibernate</property>
<!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file -->
<!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
</properties>
</entity-manager>
running code
Code:
package co.za.easypay.reportconfig;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.mysql.jdbc.Driver;
public class GetTest {
public static void main(String[]args){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");
EntityManager em = emf.createEntityManager(); // Retrieve a transactional-scoped entity manager
em.close();
emf.close();
}
}
annotated class
Code:
package co.za.easypay.reportconfig;
import java.io.Serializable;
import javax.persistence.Id;
import javax.persistence.*;
@Entity
@Table(name="person_tbl")
public class Person implements Serializable {
private Long id;
public String email_address;
@Id
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getEmail_address() {
return email_address;
}
public void setEmail_address(String email_address) {
this.email_address = email_address;
}
}