I'm trying to setup Hibernate 2.1.1 and MySql 3.23.54 for the first time using the quickstart as the basis for my experimentation.
I keep getting the follwing error:
500 Servlet Exception
java.lang.ExceptionInInitializerError
at PetitionServlet.doGet(PetitionServlet.java:14)
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.RunnerRequest.handleRequest(RunnerRequest.java:346)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:274)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:568)
Caused by: java.lang.RuntimeException: Exception building SessionFactory:
Error reading resource: Petition.hbm.xml
at at HibernateUtil.<clinit>(HibernateUtil.java:11).null(Unknown Source)
... 10 more
Caused by: net.sf.hibernate.MappingException: Error reading resource: Petition.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:307)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:957)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:909)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:845)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:831)
at at HibernateUtil.<clinit>(HibernateUtil.java:8).null(Unknown Source)
... 10 more
Caused by: net.sf.hibernate.MappingException: duplicate import: Petition
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:82)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:217)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:304)
... 15 more
I'm using the HibernateUtil pretty much verbatim.
Here's the relevant code from the servlet:
Code:
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Petition petition = new Petition();
petition.setFirst("Drew");
session.save(petition);
tx.commit();
HibernateUtil.closeSession();
Petition.hbm.xml:
Code:
<?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="Petition" table="petition">
<property name="first">
<column name="first" sql-type="varchar(16)" not-null="true"/>
</property>
</class>
</hibernate-mapping>
hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/quietzone</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<!-- Mapping files -->
<mapping resource="Petition.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I'm sure it must be a fairly simple fix.
What am I doing wrong?
Thanks,
Drew