-->
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: Hibernate setup
PostPosted: Wed Mar 24, 2004 11:06 am 
Newbie

Joined: Wed Mar 24, 2004 10:51 am
Posts: 12
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 11:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Mapped classes must declare the primary key column of the database table

http://www.hibernate.org/hib_docs/refer ... pping-s1-4


you always need to declare an id...[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 12:07 pm 
Newbie

Joined: Wed Mar 24, 2004 10:51 am
Posts: 12
OK, that worked. Thank you!

BTW, I had to add 'ehcache.jar' to my lib directory to make everything work.
I don't think this was mentioned in the quickstart. Would be a good idea to add this info, I think.

Now let's see what other kind of trouble I can get into with Hibernate. :)

Drew


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.