几天前才开始学Java,MyEclipse+struts+hibernate+mysql 的构架刚刚把struts调好,这次又遇到了hibernate的问题。还请懂hibernate的大侠为我指出问题。
按照一个教程搭的构架,运行时候有数据库操作的时候就会出错。如下
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.Hibernate.SessionFactory.currentSession(SessionFactory.java:56)
com.yourcompany.struts.form.AddAdminForm.validate(AddAdminForm.java:52)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.
--------------------------------------------
Apache Tomcat/5.5.12
我的SessionFactory是MyEclipse自动生成的,期中的代码基本没改。
package com.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html}.
*/
public class SessionFactory {
/**
* Location of hibernate.cfg.xml file.
* NOTICE: Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file. That
* is place the config file in a Java package - the default location
* is the default Java package. <br> <br>
* Examples: <br>
* <code> CONFIG_FILE_LOCATION = "/hibernate.conf.xml ".
* CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml ". </code>
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml ";
/** Holds a single instance of Session */
private static final ThreadLocal threadLocal = new ThreadLocal();