I'm new to hibernate and would appreciate any help. I'm receiving an exception "net.sf.hibernate.MappingException: No persister for: Employee" when I attempt to save a new instance of a persistent class. I'm running this code as a simple stand alone application.
Envrionment:
Hibernate 2.1.4
JDK 1.4.2
Eclipse
PostgreSQL 7.3.4
Code:
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost/treasury", "xxx", "xxx");
Configuration cfg = new Configuration();
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession(connection);
cfg.addFile("employee.hbm.xml");
Transaction tx= session.beginTransaction();
Employee emp = new Employee();
emp.setFirstName("Homer");
emp.setLastName("Simpson");
session.save(emp);
tx.commit();
Console Output:
INFO: Mapping file: employee.hbm.xml
Jun 10, 2004 5:40:27 AM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Employee -> employee
net.sf.hibernate.MappingException: No persister for: Employee
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2686)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2693)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:763)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at MyTest.main(MyTest.java:63)
Mapping File:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Employee" table="employee">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="varchar(10)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="firstName">
<column name="first_name"/>
</property>
<property name="lastName">
<column name="last_name"/>
</property>
</class>
</hibernate-mapping>
Thanks for the help
Mark
|