-->
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: org.hibernate.MappingException: entity class not found
PostPosted: Fri Oct 01, 2010 7:09 am 
Newbie

Joined: Fri Oct 01, 2010 6:35 am
Posts: 2
Hi!

I'm getting started with Hibernate. I've coded a simple web application with struts, hibernate to Oracle DB.

Hibernate complete the class mapping successfuly, but a MappingException appears because the entity class is not found.

Here is the situation...

Class hierarchy:
[ src ]
+----[ hibernate ]
+--------- Epleado.java
+--------- Empleado.hbm.xml
+--- hibernate.cfg.xml


The Tomcat's log shows (see complete LOG after explanation):
...
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - INFO org.hibernate.cfg.HbmBinder(bindRootPersistentClassCommonValues) - Mapping class: Empleado -> EMP
...

149188 [2010-10-01 11:02:10,671] [http-8080-exec-9] - ERROR hibernate.EmpleadoManager(<init>) - EmpleadoManager()
org.hibernate.MappingException: entity class not found: Empleado
...
Caused by: java.lang.ClassNotFoundException: Empleado
...

Mapping at hibernate.cfg.xml extract
Code:
<mapping resource="hibernate/Empleado.hbm.xml"/>


Mapping at Empleado.hbm.xml extract
Code:
<class name="Empleado" table="EMP" schema="SCOTT">


Searching around forums, i've found this solution: On Empleado.hbm.xml replace this line:
Code:
<class name="Empleado" table="EMP" schema="SCOTT">

with this other:
Code:
<class name="hibernate.Empleado" table="EMP" schema="SCOTT">

But, when i apply that solution, an error appears when hibernate try to do the mapping. So I supose the solution is not correct.

Any idea for solve the problem?

Thank you very much in advance !!!

Here you are the rest of the information...

Empleado.java:
Code:
package hibernate;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
* Empleado generated by hbm2java
*/
@Entity
@Table(name = "EMP", schema = "SCOTT")
public class Empleado implements java.io.Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
private short id;
private Departamento departamento;
private String nombre;
private String puesto;
private Short idManager;
private Date hireDate;
private BigDecimal salario;
private BigDecimal comision;

public Empleado() {
}

public Empleado(short id) {
this.id = id;
}

public Empleado(short id, Departamento departamento, String nombre,
String puesto, Short idManager, Date hireDate, BigDecimal salario,
BigDecimal comision) {
this.id = id;
this.departamento = departamento;
this.nombre = nombre;
this.puesto = puesto;
this.idManager = idManager;
this.hireDate = hireDate;
this.salario = salario;
this.comision = comision;
}

@Id
@Column(name = "EMPNO", unique = true, nullable = false, precision = 4, scale = 0)
public short getId() {
return this.id;
}

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DEPTNO")
public Departamento getDepartamento() {
return this.departamento;
}

public void setDepartamento(Departamento departamento) {
this.departamento = departamento;
}

@Column(name = "ENAME", length = 10)
public String getNombre() {
return this.nombre;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

@Column(name = "JOB", length = 9)
public String getPuesto() {
return this.puesto;
}

public void setPuesto(String puesto) {
this.puesto = puesto;
}

@Column(name = "MGR", precision = 4, scale = 0)
public Short getIdManager() {
return this.idManager;
}

public void setIdManager(Short idManager) {
this.idManager = idManager;
}

@Temporal(TemporalType.DATE)
@Column(name = "HIREDATE", length = 7)
public Date getHireDate() {
return this.hireDate;
}

public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}

@Column(name = "SAL", precision = 7)
public BigDecimal getSalario() {
return this.salario;
}

public void setSalario(BigDecimal salario) {
this.salario = salario;
}

@Column(name = "COMM", precision = 7)
public BigDecimal getComision() {
return this.comision;
}

public void setComision(BigDecimal comision) {
this.comision = comision;
}

}




hibernate.cfg.xml
Code:
<?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 name=""> -->
<session-factory>
  <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:rafaoracledb</property>
 
  <property name="hibernate.connection.username">SCOTT</property>
  <property name="hibernate.connection.password">tiger</property>
 
  <property name="hibernate.connection.pool_size">1</property> <!-- extra -->
  <property name="show_sql">true</property>
  <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
 
  <!-- property name="mappingDirectoryLocations">classpath:WEB-INF/classes/hibernate</property-->
 
   <!-- Archivos de mapeo -->
   <mapping resource="hibernate/Empleado.hbm.xml"/>
   <mapping resource="hibernate/Departamento.hbm.xml"/>
   
</session-factory>
</hibernate-configuration>





Empleado.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 30-sep-2010 16:42:49 by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
    <class name="Empleado" table="EMP" schema="SCOTT">
        <id name="id" type="short">
            <column name="EMPNO" precision="4" scale="0" />
            <generator class="assigned" />
        </id>
        <many-to-one name="departamento" class="Departamento" fetch="select">
            <column name="DEPTNO" precision="2" scale="0" />
        </many-to-one>
        <property name="nombre" type="string">
            <column name="ENAME" length="10" />
        </property>
        <property name="puesto" type="string">
            <column name="JOB" length="9" />
        </property>
        <property name="idManager" type="java.lang.Short">
            <column name="MGR" precision="4" scale="0" />
        </property>
        <property name="hireDate" type="date">
            <column name="HIREDATE" length="7" />
        </property>
        <property name="salario" type="big_decimal">
            <column name="SAL" precision="7" />
        </property>
        <property name="comision" type="big_decimal">
            <column name="COMM" precision="7" />
        </property>
    </class>
</hibernate-mapping>



Output LOG on Tomcat

Code:
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - INFO org.hibernate.cfg.HbmBinder(bindRootPersistentClassCommonValues)  - Mapping class: Empleado -> EMP
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: id -> EMPNO
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: departamento -> DEPTNO
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: nombre -> ENAME
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: puesto -> JOB
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: idManager -> MGR
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: hireDate -> HIREDATE
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: salario -> SAL
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.HbmBinder(bindProperty)  - Mapped property: comision -> COMM
149109 [2010-10-01 11:02:10,592] [http-8080-exec-9] - DEBUG org.hibernate.cfg.Configuration(parseMappingElement)  - null<-org.dom4j.tree.DefaultAttribute@2c06b2 [Attribute: name resource value "hibernate/Departamento.hbm.xml"]

...

149188 [2010-10-01 11:02:10,671] [http-8080-exec-9] - ERROR hibernate.EmpleadoManager(<init>)  - EmpleadoManager()
org.hibernate.MappingException: entity class not found: Empleado
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:125)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:191)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:136)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:475)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at hibernate.EmpleadoManager.<init>(EmpleadoManager.java:36)
at persistencia.EmpleadosDAO.getVectorEmpleados(EmpleadosDAO.java:31)
at negocio.ServiciosEmpleado.getVectorEmpleados(ServiciosEmpleado.java:15)
at action.ListarEmpleadosAction.execute(ListarEmpleadosAction.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:163)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:281)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1568)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Empleado
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1666)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1511)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:122)
... 78 more



Thank U !!!


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: entity class not found
PostPosted: Tue Oct 05, 2010 4:17 pm 
Newbie

Joined: Fri Oct 01, 2010 6:35 am
Posts: 2
SOLUTION:
Code:
<class name="hibernate.Empleado" table="EMP" schema="SCOTT">


It was the missing package.


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.