Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic