代码如下,是一个注册页面~
<code>
public class RegisteAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException,SQLException {
        User user = new User();

                //UserForm userForm = (UserForm)form;
//user.setLogin_id(userForm.getLogin_id());
//user.setPassword(userForm.getPassword()); user.setLogin_id(request.getParameter("login_id"));
user.setPassword(request.getParameter("password")); UserService usi = new UserServiceImpl();//Hibernate连接数据库的类
System.out.println(usi);//有实例,可以打印出结果来
System.out.println("*********");
usi.registe(user);
                     //到这一步的时候,就报错:org.hibernate.MappingNotFoundException: 
                                               resource: com/entity/User.hbm.xml not found

        return mapping.findForward("success");</code>
如果在UserService这个类中插入数据,可以正常插入,不报错,
就是用到Struts时,出现这个问题,也不知道问题出在哪,
我也用了ActionForm,可是还是同样的错误,
郁闷,这个问题已经困扰我两天了,请大虾们帮忙!~~

解决方案 »

  1.   

    这不错误已经爆出来了么,找不到映射文件啊,你应该在hibernate配置文件中写上mapping-resource
      

  2.   


    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration
        PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>        <property name="hibernate.connection.url">jdbc:mysql://localhost/student</property>        <property name="hibernate.connection.username">root</property>        <property name="hibernate.connection.password">wudi</property>        <property name="hibernate.connection.pool_size">100</property>        <property name="show_sql">true</property>
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
            
            <property name="hibernate.cache.use_query_cache">true</property> <mapping resource="student.hbm.xml"/>
        </session-factory></hibernate-configuration>
      

  3.   

    大哥,我写了mapping-resource,
    如果不是在struts中用这个类,
    在连接数据库的UserService类中,增删查改都可以,没有一点错误~
    就是跑到struts中,就冒出问题了,以前也没遇到过,
      

  4.   

    好贴出来,1、Action类,
    public class RegisterAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, SQLException {
    User user = new User();
    user.setLogin_id(request.getParameter("login_id"));
    user.setPassword(request.getParameter("password"));
    UserService us = new UserServiceImpl();
    System.out.println(us);
    us.registe(user);

    return mapping.findForward("success");
    }
    }2、Struts-config.xml<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
    <action-mappings>
    <action path="/user/registe" type="net.ezcom.linkServer.action.RegisterAction" >
    <forward name="success" path="/user/registeSuccess.jsp"/>
    </action>
    </action-mappings>
    </struts-config>3、JSP
    <form method="post" name="register" action="${pageContext.request.contextPath }/user/registe.do">
    <table align="center" width="614" cellpadding="0" cellspacing="0">
    <tr>
    <td  width="17%" class="9P">用户名*</td>
                       <td><input type="text" name="login_id"></td>
                            <td>请输入用户的帐号名称(只允许用英文,数字,下划线,区分大小写)</td>
    </tr>
    <tr>
    <td>用户密码*</td>
    <td><input type="text" name="password"></td>
                            <td> 请输入用户的帐号密码(限度为6-8位)</td>
            </tr>
             </table>
    </form>4、hibernate.cfg.xml<?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
           
    <hibernate-configuration><session-factory> <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">
    org.hibernate.cache.NoCacheProvider
    </property>
    <property name="current_session_context_class">thread</property> <property name="show_sql">true</property>
    <property name="format_sql">true</property> <!-- Add your mapping resource(.hbm.xml) here -->
    <property name="myeclipse.connection.profile">linkserver</property>
    <property name="connection.url">
    jdbc:mysql://*.*.*.*:3306/linkserver
    </property>
    <property name="connection.username">linkserver</property>
    <property name="connection.password">nokpemzw</property>
    <property name="connection.driver_class">
    com.mysql.jdbc.Driver
    </property>
    <property name="dialect">
    org.hibernate.dialect.MySQLDialect
    </property>
    <mapping resource="net/ezcom/linkserver/entity/User.hbm.xml" /></session-factory></hibernate-configuration>
    基本都帖出来,         
      

  5.   

    把STRUTS里的XML文件删除,然后从新家载一下。
      

  6.   

    org.hibernate.MappingNotFoundException:resource: com/entity/User.hbm.xml not found
    报错信息是说你的Mapping文件有问题。你把数据库的映射文件贴上来看看。
      

  7.   

    这个应该没有问题,因为我在连接数据库的类中测试时,增删查改是完全可以的,不报错,就是在Action里调用时报错了。我不知道是不是Action里面哪里写错了
      

  8.   

    org.hibernate.MappingNotFoundException:  
    resource: com/entity/User.hbm.xml not found

    注意是com/entity/User.hbm.xml这个不没找到
    不是net/ezcom/linkserver/entity/User.hbm.xml没找到
      

  9.   

    1、Action类, Java codepublic class RegisterAction extends DispathAction {    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, SQLException {
            User user = new User();
             UserForm userForm = (UserForm)form;         user.setLogin_id(userForm.getLogin_id());
            user.setPassword(userForm.getPassword());
            UserService us = new UserServiceImpl();
            System.out.println(us);
            us.registe(user);  
            return mapping.findForward("success");
        }
    }2、Struts-config.xml 
    XML code<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
        <action-mappings>
            <action path="/user" type="net.ezcom.linkServer.action.RegisterAction" >
                <forward name="success" path="registeSuccess.jsp"/>
            </action>
        </action-mappings>
    </struts-config>3、JSP HTML code<form method="post" name="register" action="user.do">
        <table align="center" width="614" cellpadding="0" cellspacing="0">
            <tr>
                <td  width="17%" class="9P">用户名*</td>
                          <td><input type="text" name="login_id"></td>
                            <td>请输入用户的帐号名称(只允许用英文,数字,下划线,区分大小写)</td>
            </tr>
                <tr>
                <td>用户密码*</td>
                <td><input type="text" name="password"></td>
                            <td> 请输入用户的帐号密码(限度为6-8位)</td>
                </tr>
             </table>
    </form>
    你试试这样做
    看行不行
      

  10.   

    晕,我也是这个问题,一直没解决,但是我用resin就没事呢,一用tomcat就报错!怎么会回事啊!