Hi,
I've checked the FAQs and I couldn't find an answer, but I keep getting:
Code:
java.lang.ExceptionInInitializerError at net.sf.hibernate.examples.quickstart.CatInsert.processRequest(CatInsert.java:59)
I am trying out the very first tutorial example in the reference documentation. It is basically copy and pasted (HibernateUtil is word for word), except for this servlet CatInsert.java. Line 59 is the HibernateUtil.currentSession() line:
Code:
package net.sf.hibernate.examples.quickstart;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.security.*;
import net.sf.hibernate.FetchMode;
import net.sf.hibernate.FlushMode;
import net.sf.hibernate.LockMode;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.cfg.Environment;
import net.sf.hibernate.expression.Example;
import net.sf.hibernate.expression.Expression;
import net.sf.hibernate.expression.MatchMode;
/** Used as a development tool to view current session data. Used during the debugging process.
* This should never make it into a release version.
* @author rpew
* @version
*/
public class CatInsert extends HttpServlet {
/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/** Destroys the servlet.
*/
public void destroy() {
}
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet</title>");
out.println("</head>");
out.println("<body>");
try{
Session session;
session = HibernateUtil.currentSession();
Transaction tx= session.beginTransaction();
Cat princess = new Cat();
String name = (String) request.getAttribute("name");
char sex = ((Character) request.getAttribute("sex")).charValue();
float weight = ((Float) request.getAttribute("weight")).floatValue();
princess.setName(name);
princess.setSex(sex);
princess.setWeight(weight);
session.save(princess);
tx.commit();
HibernateUtil.closeSession();
out.println("Cat Added.<BR><BR>");
out.println(name + "," + sex + "," + weight + "<BR><BR>");
} catch (ExceptionInInitializerError e) {
e.printStackTrace(out);
} catch (Exception e) {
e.printStackTrace(out);
}
out.println("<a href='catdisplay'>LOOK AT CATS</a>");
out.println("</body>");
out.println("</html>");
out.close();
}
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
}
[/code]