Hi I'm new to the Hibernate. I'm trying to create HelloWorld example with Hibernate. I'm trying for 3 days to deal errors. I'll be glad if anyone say what's wrong. here my hibernate user library.
"derby jar should be mysql I changed that"here's my Employee.java
Code:
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Employee {
private int empId;
private String empName;
@Id
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
}
here's my hibernate.cfg.xml file
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/HibernateDb</property>
<property name="connection.username">root</property>
<property name="connection.password">11</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">2</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's current session context -->
<property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
Drop and re-create the database schema on startup
<!-- <property name="hbm2ddl.auto">create</property>-->
<!---->
<!-- <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>-->
<!-- <mapping resource="org/hibernate/tutorial/domain/Person.hbm.xml"/>-->
</session-factory>
</hibernate-configuration>
here my run class
Code:
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class TestEmployee {
public static void main(String[] args) {
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Employee.class);
config.configure("hibernate.cfg.xml");
new SchemaExport(config).create(true, true);
}
}
When I Run the application I get these errors
Code:
01:38:48,906 INFO Version:15 - Hibernate Annotations 3.4.0.GA
01:38:48,906 INFO Environment:560 - Hibernate 3.3.2.GA
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.hibernate.cfg.Configuration.reset(Configuration.java:217)
at org.hibernate.cfg.AnnotationConfiguration.reset(AnnotationConfiguration.java:233)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:197)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:201)
at org.hibernate.cfg.AnnotationConfiguration.<init>(AnnotationConfiguration.java:108)
at com.hibernate.chapter1.TestEmployee.main(TestEmployee.java:11)
Caused by: java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:575)
... 6 more
Please help me.