-->
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.  [ 2 posts ] 
Author Message
 Post subject: com.hibernate007.pkg.Employee.class not found
PostPosted: Tue Jul 02, 2013 1:53 pm 
Newbie

Joined: Tue Jul 02, 2013 1:43 pm
Posts: 1
Location: India
HI I am getting the below error when I try and run some code using HIBERNATE.

INFO: HHH000221: Reading mappings from resource: com.hibernate007.pkg.Employee.class
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com.hibernate007.pkg.Employee.class not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:738)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2167)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2139)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2119)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2072)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1987)
at com.hibenate007.pkg.MySessionFactory.getSession(MySessionFactory.java:11)
at com.hibenate007.pkg.ClientProgram.main(ClientProgram.java:12)



Below given all the codes that I have written.

hibernate.cfg.xml

<?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="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernatedata</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com.hibernate007.pkg.Employee"/>
</session-factory>

</hibernate-configuration>

POJO class

package com.hibenate007.pkg;

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;
}


}

SessionFactory Class

package com.hibenate007.pkg;


import org.hibernate.*;
import org.hibernate.cfg.Configuration;
public class MySessionFactory {

static Session getSession(){
Configuration conf = new Configuration();

conf.configure("hibernate.cfg.xml");
@SuppressWarnings("deprecation")
SessionFactory sf = conf.buildSessionFactory();
return sf.openSession();
}

}

And finally the calling class(Client Program)

package com.hibenate007.pkg;


import org.hibernate.Session;


public class ClientProgram {


public static void main(String[] args) {

Session session = MySessionFactory.getSession();
session.beginTransaction();
Employee emp =new Employee();
emp.setEmpid(1);
emp.setEmpname("aneek");
session.save(emp);

session.getTransaction().commit();

session.close();



}

}


I am a newbie to Hibernate.Please help me to solve this I am trying to figure this problem for last 2 days.Even checked in internet also but not accquired any proper steps.

Please help ASAP.

Thanks in advanced. :)


Top
 Profile  
 
 Post subject: Re: com.hibernate007.pkg.Employee.class not found
PostPosted: Sun Jul 28, 2013 8:15 am 
Newbie

Joined: Fri Jul 26, 2013 8:04 am
Posts: 2
Hi Aneekbanerjee86 and welcome to Hibernate.

The problem is in the following code:

<mapping resource="com.hibernate007.pkg.Employee"/>

It needs to be mapped an "hbm.xml" file that is available in the package you mapped, meaning "com.hibernate007.pkg", and it should use a slash ("/") notation and not a dot (.) notation.
So create an "Employee.hbm.xml" file in the package "com.hibernate007.pkg" and change the mapping to "com/hibernate007/pkg/Employee.hbm.xml".

There is also a nice tutorial in: "http://ejbas-hibernate.blogspot.co.il/", that explains how to use Hibernate in a really neat and detailed step-by-step.

Good luck


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

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.