-->
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.  [ 3 posts ] 
Author Message
 Post subject: No persister for: ClassName
PostPosted: Thu Jun 10, 2004 7:14 am 
Newbie

Joined: Thu Jun 10, 2004 7:01 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 7:30 am 
Newbie

Joined: Sat Oct 11, 2003 1:47 pm
Posts: 17
cfg.addFile("employee.hbm.xml");

should go before you create the session object.

so it should be something like
Configuration cfg = new Configuration();
cfg.addFile("employee.hbm.xml");
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession(connection);


Cheers
Raja


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 9:11 pm 
Newbie

Joined: Thu Jun 10, 2004 7:01 am
Posts: 2
Thanks for the help. That solved it.

Mark


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