The moose likes Object Relational Mapping and the fly likes First timer with Hibernate - unknown entity error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "First timer with Hibernate - unknown entity error" Watch "First timer with Hibernate - unknown entity error" New topic
Author

First timer with Hibernate - unknown entity error

Raphael Rissato
Greenhorn

Joined: May 10, 2007
Posts: 6
Hi, heres my problem: when I use "cfg.addClass(Tarifa.class)" to map a class I get the following error (since its already mapped at hibernate.cfg.xml):

org.hibernate.MappingException: Error reading resource: Tarifa.hbm.xml
at org.hibernate.cfg.Configuration.addClass(Configuration.java:471)
at TarifaDAO.<init>(TarifaDAO.java:12)
at TesteHib.main(TesteHib.java:10)
Caused by: org.hibernate.MappingException: duplicate import: Tarifa

if I comment the "cfg.addClass(Tarifa.class)", I get the (funny if not tragic) error:

org.hibernate.MappingException: Unknown entity: from Tarifa
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFacto
ryImpl.java:569)
at org.hibernate.impl.SessionImpl.getOuterJoinLoadable(SessionImpl.java:
1337)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1303)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at TarifaDAO.getList(TarifaDAO.java:24)
at TesteHib.main(TesteHib.java:11)
Press any key to continue...

Please help me if you know whats happening. Tkx!
sathish kumar
Ranch Hand

Joined: Feb 14, 2007
Posts: 47
Can you copy paste your code for hibernate.cfg.xml and Tarifa entity.
Raphael Rissato
Greenhorn

Joined: May 10, 2007
Posts: 6
hibernate.cfg.xml ========================================================

<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/minhaconta</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<mapping resource="Tarifa.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>

Tarifa.cfg.xml ==============================================================

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping.dtd">
<hibernate-mapping>
<class name="Tarifa" table="tarifa">
<id name="cod" column="cod" type="int">
<generator class="assigned"/>
</id>
<property name="valor" type="double"/>
<property name="dia" type="string"/>
<property name="horaInicio" type="string"/>
<property name="horaFim" type="string"/>
<property name="tipo" type="string"/>
</class>
</hibernate-mapping>
Jaikiran Pai
Saloon Keeper

Joined: Jul 20, 2005
Posts: 6718

<mapping resource="Tarifa.hbm.xml"></mapping>


Where is the Tarifa.hbm.xml placed in your application?


[My Blog] [JavaRanch Journal]
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
Hi,

It is not finding the path of <mapping resource="Tarifa.hbm.xml"></mapping>

get the path and specify ...............the project path
Raphael Rissato
Greenhorn

Joined: May 10, 2007
Posts: 6
Hi... there�s no package in my app. All files class and all xml files are placed at the same dir. Tkx
sathish kumar
Ranch Hand

Joined: Feb 14, 2007
Posts: 47
You might want to create a package com.hibernate.example and put your Java file in it. As well tweak the hbm file's class parameter to
<class name="com.hibernate.example.Tarifa" table="tarifa">
 
IntelliJ Java IDE
 
subject: First timer with Hibernate - unknown entity error
 
Threads others viewed
Entity class not found/InvocationTargetException
Problem of Unknown Entity
org.hibernate.MappingException: Unknown entity
Unknown entity: java.util.ArrayList ???
hbm file version working but annotation not
developer file tools