wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark ""main" org.hibernate.MappingException: Unknown entity:  Hibernate" Watch ""main" org.hibernate.MappingException: Unknown entity:  Hibernate" New topic
Author

"main" org.hibernate.MappingException: Unknown entity: Hibernate

harringbone developer
Greenhorn

Joined: Apr 24, 2013
Posts: 1
Hi,

I am getting "Exception in thread "main" org.hibernate.MappingException: Unknown entity: onetomany.Emp" Exception.

my files are like :
emp.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="Emp" table ="employee">

<id name="Empid" type="int" column="empid">
<generator class="incremental"/>
</id>

<property name="Empname" column="empname" type="string" length ="10"/>

<set name="Empdtls" table ="empdtls" inverse="true" lazy="true" fetch="select">
<key>
<column name="Empid" not-null="true"/>
</key>
<one-to-many calss="Empdtls" />
</set>
</class>
</hibernate-mapping>

empdtls.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Empdtls" table="empdtls" >

<id name="EmpDtlsId" type="int" column="empid">
<generator class="incremental"/>
</id>

<many-to-one name="emp" class="Emp" fetch="select">
<column name="emp" not-null="true"/>
</many-to-one>

<property name="EmpDtlsData" column="empdata" type="string" lenght="10"></property>
<property name="EmpdtlsFullname" column="empfullname" type="string" lenght="11"></property>
</class>
</hibernate-mapping>

java class:
EmpManager

package onetomany;

import hibernatetest.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class EmpManager {

static SessionFactory sesfac;

public static void main(String[] args) {

System.out.println("Hibernate one to many (XML Mapping)");
sesfac=HibernateUtil.getSessionFactory();

Session session = sesfac.openSession();
session.beginTransaction();

Emp emp = new Emp();
emp.setEmpid(7052);
emp.setEmpname("PADINI");
session.save(emp);

Empdtls empdtls = new Empdtls();
empdtls.setEmpDtlsId(121);
empdtls.setEmpDtlsData("empdata");
empdtls.setEmpdtlsFullname("empfullname");


empdtls.setEmp(emp);
emp.getEmpdtls().add(empdtls);

session.save(empdtls);

session.getTransaction().commit();
System.out.println("Done");

}

}

Empdtls
package onetomany;

import java.io.Serializable;

public class Empdtls implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
int EmpDtlsId;
String EmpDtlsData;
String EmpdtlsFullname;
Emp emp;

public int getEmpDtlsId() {
return EmpDtlsId;
}
public void setEmpDtlsId(int empDtlsId) {
EmpDtlsId = empDtlsId;
}
public String getEmpDtlsData() {
return EmpDtlsData;
}
public void setEmpDtlsData(String empDtlsData) {
EmpDtlsData = empDtlsData;
}
public String getEmpdtlsFullname() {
return EmpdtlsFullname;
}
public void setEmpdtlsFullname(String empdtlsFullname) {
EmpdtlsFullname = empdtlsFullname;
}
public Emp getEmp() {
return emp;
}
public void setEmp(Emp emp) {
this.emp = emp;
}



}

Emp

package onetomany;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class Emp implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
int Empid;
String Empname;
public Set<Empdtls> empdtls = new HashSet<Empdtls>();

public int getEmpid() {
return Empid;
}
public void setEmpid(int empid) {
Empid = empid;
}
public String getEmpname() {
return Empname;
}
public void setEmpname(String empname) {
Empname = empname;
}
public Set<Empdtls> getEmpdtls() {
return empdtls;
}
public void setEmpdtls(Set<Empdtls> empdtls) {
this.empdtls = empdtls;
}



}

In my hbm.xml file previously i have written like <class name="onetomany.Emp" table ="employee"> & <class name="onetomany.Empdtls" table="empdtls" >

at that time mention problem has occurred but after changing class name in both hbm.xml files, I am still getting the same problem.

Can any one help me out .


Please any one let me why this
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: "main" org.hibernate.MappingException: Unknown entity: Hibernate