在使用hibernate时出现java.lang.NoClassDefFoundError: net/sf/hibernate/SessionFactory错误

wzx7934003 2005-04-06 04:18:12
各位兄弟,我在使用hibernate时出现java.lang.NoClassDefFoundError: net/sf/hibernate/SessionFactory错误,请问该怎么解决。
以下是我的文件,主要是在执行execute方法时出现了这个错误。

package addressbook.actions;

import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import addressbook.forms.InsertForm;
import addressbook.bookinfo.*;
import addressbook.Constants;
import addressbook.hibernate.*;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;


/**
* <strong>InsertAction</strong> inserts a new record into the database.
*/
public final class InsertAction extends HibernateBase {
public InsertAction()throws Exception
{
super();
}

private Log log =
LogFactory.getLog(this.getClass().getName());

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


Locale locale = getLocale(request);
MessageResources messages = getResources(request);


String name=null;
String phone=null;
String address=null;

ActionMessages errors = new ActionMessages();

name = ((InsertForm) form).getName();
phone=((InsertForm)form).getPhone();
address=((InsertForm)form).getAddress();

try
{
AddressbookTable bean=new AddressbookTable();
bean.setAddress(address);
bean.setPhone(phone);
bean.setName(name);

beginTransaction();
session.save(bean);
endTransaction(true);


}
catch(Exception ex)
{
ex.printStackTrace(System.out);
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("error.insert.failed"));
}

if (!errors.isEmpty()) {
saveMessages(request, errors);
return (new ActionForward(mapping.getInput()));
}
// If we had no errors, then add a confirmation message
ActionMessages actionMessages = new ActionMessages();
actionMessages.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("record.inserted"));
saveMessages(request,actionMessages);

return (mapping.findForward(Constants.FORWARD_CONFIRMATION));

}
}
...全文
429 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dakuntk 2005-04-08
  • 打赏
  • 举报
回复
嘿嘿~~不说啥了,接分!

path问题,检查
RomandAccessFile 2005-04-08
  • 打赏
  • 举报
回复
导入你的Hibernate2.jar搞定,

我脸皮厚来,接分
asdmonster 2005-04-06
  • 打赏
  • 举报
回复
简单的说呢,连接的时候没有找到你的jar,
通俗的说呢,你的jar没有在你的执行环境的classpath里面
玩笑的说呢,这么常见的问题,亏你也不自己找找原因,也只有我这种无聊的人接分了。

^_^
wzx7934003 2005-04-06
  • 打赏
  • 举报
回复
有哪位大哥能帮帮忙吗

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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