• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

First timer with Hibernate - unknown entity error

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you copy paste your code for hibernate.cfg.xml and Tarifa entity.
 
Raphael Rissato
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Where is the Tarifa.hbm.xml placed in your application?
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic