Javatpoint Logo

Error in Running Hibernate with eclipse

By: gaurav*** On: Thu Mar 21 16:32:08 IST 2013     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
I copied complete code in my eclipse & is trying to execute but I am getting following error.


Employee.java

package com.hibernate.basic;

public class Employee {

private int id;
private String FName, LName;

public String getFName() {

return FName;
}

public void setFName(String FName) {

this.FName = FName;
}

public String getLName() {
return LName;
}

public void setLName(String LName) {

this.LName = LName;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}



StoreData.java

package com.hibernate.basic;

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.setFName("sonoo");
e1.setLName("jaiswal");

session.persist(e1);// persisting the object

t.commit();// transaction is commited
session.close();

System.out.println("successfully saved");

}
}


employee.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping>


<class name="com.hibernate.basic.Employee" table="EMPLOYEE" lazy="false">

<id name="id" column="EMPID" type="int">

<generator class="increment"></generator>
</id>

<property name="FName" column="NAME"></property>
<property name="LName" column="LNAME"></property>

</class>

</hibernate-mapping>

hibernate.cfg.xm

<?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>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@172.16.3.94:1521:EAMABP</property>
<property name="connection.username">EAM</property>
<property name="connection.password">EAM</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.Oracle10Dialect</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="employee.hbm.xml"/>
</session-factory>

</hibernate-configuration>

error

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
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:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at com.hibernate.basic.St
Up0Down

 
There is nothing I think so. You just change your employee.hbm.xml filename to Employee.hbm.xml.This name should be mapped with Employee bean i.e Employee.java
and also you should change in hibernate.cfg.xml file also.
Image Created0Down

By: [email protected] On: Thu Mar 21 19:01:51 IST 2013 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes5No