Hibernate: “No persister for” error
Monday, April 12th, 2004I’m pulling my hair out trying to fix this error. I’ve used the same technique, similar datatypes, similar mapping files…yet, when I try to map my Hibernate “Historical” data object class, I get a “No persister for” error. I’ve googled for solutions to this problem, but nothing has come up applicable to what I’m looking to fix. So, I’m turning to the blogosphere for help here.
In order to debug, I’ve created a servlet which attempts to write a data object (Historical) to MySQL. I do this twice, with the same code (copy & paste for this junk debug code). One method (writeDailysumsToDB) writes to a different data object, with similar types. The second method (writeHistoricalToDB) writes the Historical data object. writeDailysumsToDB works perfectly, yet writeHistoricalToDB fails with the mentioned “No persister for” error. This leads me to believe it’s a mapping error, yet I can’t detect where. So I’m dumping everything here in the hopes someone can browse and point out my obvious error.
—– Exception stacktrace —–net.sf.hibernate.MappingException: No persister for: db.Historical
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:420)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2302)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2309)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:599)
at spike.WriteHistoricalServlet.writeHistoricalToDB(WriteHistoricalServlet.java:192)
at spike.WriteHistoricalServlet.handleRequest(WriteHistoricalServlet.java:126)
at org.apache.velocity.servlet.VelocityServlet.doRequest(VelocityServlet.java:372)
at org.apache.velocity.servlet.VelocityServlet.doGet(VelocityServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:164)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:536)—– hibernate mapping File —–
<?xml version=”1.0″?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 2.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd”>
<hibernate-mapping>
<class name=”db.Historical” table=”historical” >
<id name=”id” column=”id” type=”int” unsaved-value=”null”>
<generator class=”native”>
</generator>
</id>
<property name=”datelog” type=”java.util.Date” column=”datelog” not-null=”true”/>
<property name=”opened_this_day” type=”int” column=”open_this_day” not-null=”true”/>
<property name=”closed_this_day” type=”int” column=”closed_this_day” not-null=”true”/>
<property name=”open_all” type=”int” column=”open_all” not-null=”true”/>
</class>
</hibernate>CREATE TABLE historical (
id bigint(5) unsigned NOT NULL auto_increment,
datelog date default ‘2001-01-01′,
opened_this_day bigint(5) unsigned default ‘0′,
closed_this_day bigint(5) unsigned default ‘0′,
open_all bigint(5) unsigned default ‘0′,
PRIMARY KEY (id)
) TYPE=ISAM;——Data object——
public class Historical {
…
private int id;
private Date datelog;
private int opened_this_day;
private int closed_this_day;
private int open_all;
…——method in servlet to write data Object——
private boolean writeHistoricalToDB ( Historical historical ) {
boolean result = true;
Transaction tx = null;
try {
SessionFactory sf = new Configuration().configure(”/config.cfg.xml”).buildSessionFactory();
Session sess = sf.openSession();
try {
tx = sess.beginTransaction();
sess.save(historical);
tx.commit();
} catch (HibernateException he) {
if (tx != null) tx.rollback();
result = false;
log.warn(”EXCEPTION: ” + he.getMessage(), he);
} finally {
sess.close();
}
} catch (HibernateException he) {
result = false;
log.warn(”EXCEPTION: ” + he.getMessage(), he);
}
return result;
}//writeHistoricalToDB
UPDATE: Matt Raible solved the problem for me (an hour after posting!). As I suspected, a stupid mistake…I forgot to add the .hbm.xml file to the cfg.xml file. Hopefully google will index and it’ll be a reference in case others have the same problem.



