-->
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.  [ 6 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Cat
PostPosted: Thu May 12, 2005 2:46 pm 
Newbie

Joined: Tue May 03, 2005 8:02 pm
Posts: 13
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I'm following the Cat example in the Hibernate 3.0 guide.

I'm using Eclipse. Hibernate, the JDBC driver, etc., are in the Eclipse build path.

The hibernate.cfg.xml file, my Cat.hbm.xml file and my Cat.java file are all in the same folder: src/com/rps/hibernate and compiled to the same folder bin/com/rps/hibernate.

The test application is in the same directory, too.

My Java class starts like this:

package com.rps.hibernate;
public class Cat {
...
}

The error message sounds like the Hibernate equivalent of ClassNotFound. But I don't know what to do to fix it.

Thanks

Any suggestions for what I might be doing wrong?
Hibernate version:
3.0

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mappint DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.rps.hibernate.Cat" table="CAT" >
      
   <id name="id" type="string" unsaved-value="null">
    <column name="CAT_ID" sql-type="char(32)" not-null="true" />
    <generator class="uuid.hex" />
   </id>
      
   <property name="name">
    <column name="NAME" length="16" not-null="true" />
   </property>
      
   <property name="sex" />
   <property name="weight" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
I'm using the HibernateUtil sample class from the manual. This is the code that calls the methods in HibernateUtil:
Code:
  Transaction tx = session.beginTransaction();
  Cat princess = new Cat();
  princess.setName("Princess");
  princess.setSex('F');
  princess.setWeight(7.4f);
      
  session.save(princess);
tx.commit();


Full stack trace of any exception that occurs:
(If anyone knows how to fix the logger problem I'd appreciate it)
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.MappingException: Unknown entity: com.rps.hibernate.Cat
   at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:489)
   at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1014)
   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:429)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
   at com.rps.hibernate.TestCat.main(TestCat.java:26)
Exception in thread "main"

Name and version of the database you are using:
SQL Server 200

The generated SQL (show_sql=true):
Don't
Debug level Hibernate log excerpt:
Can't find any in Hibernate console and I don't think the logger is working.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 3:09 pm 
Newbie

Joined: Wed May 04, 2005 1:10 pm
Posts: 8
Do you have asm.jar in your WEB-INF/lib area? I think I found out today that this is also needed. Please let me know if this fixes things for you as I am trying to determine whether this is really a documentation bug or not.

_________________
There's lies, damn lies and slashdot.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 3:13 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Most likely, the com.rps.hibernate.Cat class is not defined in the hibernate.properties, hibernate.cfg.xml or in the code where you are creating your SessionFactory.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 3:21 pm 
Newbie

Joined: Tue May 03, 2005 8:02 pm
Posts: 13
Learjet: I'm not running this in a web container. But no, I don't have the asm.jar in hibernate\lib. I'm sure I unzipped the library correctly, so I don't know how I'd be missing it.

pksiv: I can't find a mention in the Hib 3 Ref Docs about putting class definitions in hibernate.properites or hibernate.cfg.xml. I thought we just put hbm.xml files in a directory and we were golden...?

How woudl I do that?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 3:25 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
shp.jc wrote:
Learjet: I'm not running this in a web container. But no, I don't have the asm.jar in hibernate\lib. I'm sure I unzipped the library correctly, so I don't know how I'd be missing it.

pksiv: I can't find a mention in the Hib 3 Ref Docs about putting class definitions in hibernate.properites or hibernate.cfg.xml. I thought we just put hbm.xml files in a directory and we were golden...?

How woudl I do that?


Read Chapter 4. Configuration of the reference docs. (I think it's ch 3 for prior to v3.0.3)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 3:52 pm 
Newbie

Joined: Tue May 03, 2005 8:02 pm
Posts: 13
That did it. I totally missed that in the Chapter.

I guess I was a little too eager!

Thanks
Scott


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