-->
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.  [ 4 posts ] 
Author Message
 Post subject: Can't put files in packages
PostPosted: Sat Jul 23, 2005 7:32 pm 
Newbie

Joined: Sat Jul 23, 2005 7:19 pm
Posts: 11
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2005 11:04 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
how are you creating your SessionFactory? In my experience the

<mapping resource="/prueba/datos/Event.hbm.xml"/>

style of importing configurations is problematic; not through any fault of hibernate, but simply because the path has to be exactly right. Try pulling this out of your mapping file and when you create your Configuration, use addClass(), instead. To be specific, separate the non-entity mapping stuff into a hibernate.cfg.xml and place that in the root of your project (no package). Then place Event related mapping data in Event.hbm.xml, which should be stored in the package with Event.java. If you do all of this, you should be able to create a SessionFactory with the code mentioned at the bottom of the post you pointed to:

Code:
sessionFactory = new Configuration()
                         .addClass(Event.class)
                         .configure()
                         .buildSessionFactory();


If not, post the code you need to initialize your SessionFactory, and maybe we can figure something out from that.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 24, 2005 1:51 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
As you are already specifying the package name at "hibernate-mapping" element, your mapping resource should look like this.

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

I think this should work!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 24, 2005 4:27 pm 
Newbie

Joined: Sat Jul 23, 2005 7:19 pm
Posts: 11
This is a really fast forum! You answer on Sunday!
Thank you very much Eagle, I could solve my problem, and I took your advice of removing mapping resource from hibernate configuration file. Nonetheless, what really solved my problem was that hibernate.cfg.xml was not on root package, I moved it to non-package (<default root> on NetBeans) and everything worked fine.
But... I am a bit stubborn (well, a lot really) I tried with the old configuration and it still worked, that's why I say that all I had to do was to move the package.
Hibernate is not simple, but with this kind of forum I understand why it is so popular ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.