jsp+javaBean+hibernate 執行時報錯,大家幫著看看!

aill發表於2004-12-24
錯誤是:
root cause

java.lang.ExceptionInInitializerError
test.Student.selectHBM(test.java:262)
org.apache.jsp.register_jsp._jspService(register_jsp.java:150)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


程式碼是
public boolean selectHBM() throws Exception {
Session session = HibernateUtil.currentSession(); //就是這裡出錯
try {
String queryString = "select test.Student from test.Student as stu where stu.userid='"+userid+"'";
Query query = session.createQuery(queryString);
Iterator it = query.iterate();
if(it.hasNext()){
Student stu=(Student)it.next();
username = stu.getUsername();
sex = stu.getSex();
birthday = stu.getBirthday();
email = stu.getEmail();
address = stu.getAddress();
phone = stu.getPhone();
cardnumber = stu.getCardnumber();
regip = stu.getRegip();
regdate = stu.getRegdate();
return true;
}else{
return false;
}


} catch (Exception he) {
throw new Exception(he);
} finally {
HibernateUtil.closeSession();
}

}
這個方法主要用來查詢某個編號的學生,有的話初始化他

下面這個工具類也沒錯啊,編譯透過了
import java.io.InputStream;
import java.util.Properties;
package test;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}

public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
我分析是執行的時候找不到需要的hibernate類庫
但是我把hibernate所需要的包全部複製到 web-inf\lib裡了啊
hibernate所需要的配置檔案hibernate.cfg.xml和Student_hbm.xml也都在web-inf\class下啊

那位朋友指點一下

相關文章