This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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

harringbone developer

Joined: Apr 24, 2013
Posts: 1

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

my files are like :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<class name="Emp" table ="employee">

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

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

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


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

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

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

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

java class:

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)");

Session session = sesfac.openSession();

Emp emp = new Emp();

Empdtls empdtls = new Empdtls();





package onetomany;


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;



package onetomany;

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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: "main" org.hibernate.MappingException: Unknown entity: Hibernate
It's not a secret anymore!