当前位置: 代码迷 >> Eclipse >> eclipse+strust+hibernate一个奇怪的有关问题!
  详细解决方案

eclipse+strust+hibernate一个奇怪的有关问题!

热度:91   发布时间:2016-04-23 18:39:51.0
eclipse+strust+hibernate一个奇怪的问题!在线等!
eclipse+strust+hibernate,做一个小demo主要的功能是讲表单中的数据持久化的数据库中,在单独调用hibernate的情况下是可以写入数据库的,然后,写一个test代码如下

package   com.hibmapping;

import   org.hibernate.*;
import   org.hibernate.cfg.*;


public   class   Test   {
public   void   insert(String   Username,String   Userpwd)   {
try   {
SessionFactory   sf   =   new   Configuration().configure().buildSessionFactory();
Session   session   =   sf.openSession();
Transaction   tx   =   session.beginTransaction();
Userlist   user   =   new   Userlist();
user.setUsername(Username);
user.setUserpwd(Userpwd);
session.save(user);
tx.commit();
session.close();
}   catch   (HibernateException   e)   {
e.printStackTrace();
}
}
public   static   void   main(String[]   args)   {
Test   test=new   Test();
test.insert( "w ", "wf ");

}

}
后在Action中execute调用insert报错,
exception  

javax.servlet.ServletException:   Servlet   execution   threw   an   exception


root   cause  

java.lang.NoClassDefFoundError:   org/hibernate/HibernateException
com.struts.action.HihibAction.execute(HihibAction.java:46)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Action中的execute函数

public   ActionForward   execute(
ActionMapping   mapping,
ActionForm   form,
HttpServletRequest   request,
HttpServletResponse   response){

                                    HihibForm   hihibForm   =   (HihibForm)   form;
System.out.println( "call   execute ");
Test   test=new   Test();
test.insert( "wufei ", "success!@ ");
return   mapping.findForward( "hihib_forward ");
}

------解决方案--------------------
应该是少包
------解决方案--------------------
是不是把文件复制到WebRoot\WEB-INF\lib下面就可以了?
------解决方案--------------------
关注
------解决方案--------------------
你是不是用的Hibernate 3啊?
要手动加一些jar的
------解决方案--------------------
你的*.hbm.xml中的*.java路径设错了
详情请加好友QQ;258504084
E-MAIL;lvsb5126a@163.com
代码迷推荐解决方案:java.lang.NoClassDefFoundError: org/hibernate/HibernateException,http://www.daimami.com/search?q=10135
  相关解决方案