jsp+javaBean+hibernate 运行时报错,高手帮着看看!

ailling 2004-12-24 04:39:56
错误是:
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下啊

那位朋友指点一下
...全文
114 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Neo 2005-01-03
  • 打赏
  • 举报
回复
我也遇到了相同的问题,楼主能不能把解决方法贴出来呀?
ailling 2004-12-29
  • 打赏
  • 举报
回复
问题解决
fashchina 2004-12-25
  • 打赏
  • 举报
回复
确保数据能连上吗?
ailling 2004-12-25
  • 打赏
  • 举报
回复
hibernate包没问题啊,编译都通过了啊,而且hibernate所需要的所有包都在web-inf\lib目录下
奇怪了,哪里出错呢
fengyun1314 2004-12-24
  • 打赏
  • 举报
回复
圣诞节快乐
loverisyour 2004-12-24
  • 打赏
  • 举报
回复
Student_hbm.xml 这个应该和Student类同一路径
确定你的hibernate包是好的?
ailling 2004-12-24
  • 打赏
  • 举报
回复
hibernate.cfg.xml在web-inf\class下
Student_hbm.xml在web-inf\class\test下
运行还是出错
bluemeteor 2004-12-24
  • 打赏
  • 举报
回复
Student_hbm.xml 这个应该和Student类同一路径

不过好像不是这个引起的....总之楼主先改一下

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧