I am very new to Hibernate ,http://www.javatpoint.com/example-to-create-hibernate-application-in-eclipse-ide
I followed this link to create a Hibernate application,but i am getting th e following error:
11:31:31,707 INFO [main] Environment:584 - using JDK 1.4 java.sql.Timestamp handling
11:31:31,738 INFO [main] Configuration:1423 - configuring from resource: hibernate.cfg.xml
11:31:31,738 INFO [main] Configuration:1400 - Configuration resource: hibernate.cfg.xml
11:31:33,501 INFO [main] Configuration:553 - Reading mappings from resource : employee.hbm.xml Exception in thread "main" org.hibernate.MappingNotFoundException: resource: employee.hbm.xml not found at org.hibernate.cfg.Configuration.addResource(Configuration.java:563) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1584) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505) at org.hibernate.cfg.Configuration.configure(Configuration.java:1425) at pack.storedata.main(storedata.java:13)
hibernate.cfg.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
root
</property>
<!-- List of XML mapping files -->
<mapping resource="employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
employee.hbm.xml:
<?xml version='1.0'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-mapping>
<class name="pack.employee" table="emp1000">
<id name="id">
<generator class="assigned"></generator>
</id>
<property name="firstName"></property>
<property name="lastName"></property>
</class>
</hibernate-mapping>
storedata.java:
package pack;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class storedata {
public static void main(String[] args) {
//creating configuration object
Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file
//creating seession factory object
SessionFactory factory=cfg.buildSessionFactory();
//creating session object
Session session=factory.openSession();
//creating transaction object
Transaction t=session.beginTransaction();
employee e1=new employee();
e1.setId(115);
e1.setFirstName("sonoo");
e1.setLastName("jaiswal");
session.persist(e1);//persisting the object
t.commit();//transaction is committed
session.close();
System.out.println("successfully saved");
}
}
employee.java:
package pack;
public class employee {
private int id;
private String firstName,lastName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Project Structure:
Hibernate
->src
->pack
->employee.java
->storedata.java
-> employee.hbm.xml
-> hibernate.cfg.xml