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.