-->
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.  [ 2 posts ] 
Author Message
 Post subject: ExceptionInInitializerError
PostPosted: Thu Nov 27, 2003 9:35 am 
Newbie

Joined: Thu Nov 27, 2003 9:11 am
Posts: 5
I have been unable to run the simple example below. It is a servlet which should update a mysql database with a table called cat. The table fields are
cat_id, int
name, varchar
sex, char
weight, float

The servlet is as follows:
Code:
...
import net.sf.hibernate.Session;
import java.io.PrintWriter;

public class UpdateServlet extends HttpServlet {
   protected void doPost(
      HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {
            
      SessionFactory sessionFactory = null;
      Session session = null;
      Transaction transaction = null;
      Configuration cfg = null;
      try {
         PrintWriter out = response.getWriter();
         out.println("inside update servlet");
         cfg = new Configuration().configure();  // error line 31 here
         
         // also tried ff also error
         // cfg = new Configuration()
         //   .addClass(net.sf.hibernate.testwebapp.quickstart.Cat.class);

         sessionFactory = cfg.buildSessionFactory();
         session = sessionFactory.openSession();
         transaction = session.beginTransaction();
         Cat domestic = new Cat();
         domestic.setName("lingoName");
         domestic.setSex('M');
         domestic.setWeight(123.0F);
         session.save(domestic);
         transaction.commit();
         session.close();
      }catch(Exception e){
         e.printStackTrace();
      }
   }
}


The Cat class is as follows
Code:
package net.sf.hibernate.testwebapp.quickstart;
public class Cat {
   private int id;
   private String name;
   private char sex;
   private float weight;
   public Cat() {}
   public int getId() { return id; }
   public void setId(int id) { this.id = id; }
   public String getName() { return name; }
   public void setName(String name) { this.name = name; }
   public char getSex() { return sex; }
   public void setSex(char sex) { this.sex = sex; }
   public float getWeight() { return weight; }
   public void setWeight(float weight) { this.weight = weight; }
}


My Cat.hbm.xml file (which is in the same folder as my Cat.class) is as follows:
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="net.sf.hibernate.testwebapp.quickstart.Cat" table="cat">
        <id name="id" type="int" column="cat_id" >
            <generator class="native" />
        </id>
        <property name="name"/>
        <property name="sex"/>
        <property name="weight"/>
    </class>
</hibernate-mapping>


I also tried generator class="identity" & "sequence" above, still didnt run.

My hibernate.cfg.xml (in WEB-INF\classes) is as follows
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 name="java:comp/env/hibernate/SessionFactory">
        <property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
        <property name="show_sql">false</property>
        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

        <!-- Mapping files -->
        <mapping resource="/net/sf/hibernate/testwebapp/quickstart/Cat.hbm.xml"/>

    </session-factory>
</hibernate-configuration>


Kindly explain why the following error shows in the browser when I run the servlet
Code:
exception
javax.servlet.ServletException: Servlet execution threw an exception
...
root cause

java.lang.ExceptionInInitializerError
   at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
   at net.sf.hibernate.testwebapp.quickstart.UpdateServlet.doPost(UpdateServlet.java:31)
...


The following lines are at the end of the log file.
Code:
...
INFO: Mapping resource: /net/sf/hibernate/testwebapp/quickstart/Cat.hbm.xml
Nov 27, 2003 7:21:33 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: net.sf.hibernate.testwebapp.quickstart.Cat -> cat
Nov 27, 2003 7:21:34 PM net.sf.hibernate.cfg.Configuration configure
INFO: Configured SessionFactory: java:comp/env/hibernate/SessionFactory
Nov 27, 2003 7:21:34 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Nov 27, 2003 7:21:34 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints


Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 12:24 pm 
Newbie

Joined: Thu Nov 27, 2003 9:11 am
Posts: 5
I got it now! It was so draining.

My WEB-INF/lib needs to have cglib-asm.jar to eliminate those errors. Originally, I had cglib-1.0.jar because it was what was stated in the description and it was what came with the sample files.

I came to find out about the discrepancy when I did another more simple sample. One that's command line and not a webapp. I made a build file which included running the compiled program. At least the errors were more clear for this other app e.g. no class definition exceptions for missing class files. I had to do trial and error in putting the appropriate jar file until there were no errors (with the deployment of cglib-asm). I compared the lib contents of this and that of the other one above and saw the difference.


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