Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi, I was doing first examples in hibernate tutorial, all worked until I put files into packages. I read that another guy had the same problem in
http://forum.hibernate.org/viewtopic.ph ... ht=package, but it didn't work for me, I still have a Mapping Exception. I also read in Javadoc that this is a configuration problem, not runtime problem, what could be wrong?
Hibernate version:
3.0.5
Mapping documents:
Event.hmb.xml
Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
session.save(theEvent);
tx.commit();
Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: prueba.datos.Event
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:569)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1086)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:83)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
at prueba.logica.EventManager.createAndStoreEvent(EventManager.java:36)
at prueba.logica.EventManager.main(EventManager.java:15)
Java Result: 1
Name and version of the database you are using:
SQLServer 2000 with jTDS
The generated SQL (show_sql=true):
it doesn't generate any SQL (but when files where in no package it generated an insert statement)
My code:
EVENT.HBM.XML (in prueba.datos package)
<?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 package="prueba.datos">
<class name="Event"
table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="title"/>
</class>
</hibernate-mapping>
HIBERNATE.HBM.XML (in prueba.logica package)
<?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>
<!-- Database connection settings -->
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://federico:1991/cuadradov2</property>
<property name="connection.username">redondex</property>
<property name="connection.password">cuadradongo</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">50</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.idle_test_period">3000</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">create</property> -->
<mapping resource="/prueba/datos/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Event.java is in prueba.datos package