1

私は取得しています: HTTP ステータス 500 -type 例外レポート

-メッセージの説明: 「サーバーで内部エラー () が発生したため、この要求を実行できませんでした」.

-例外: org.hibernate.InvalidMappingException: リソース user.hbm.xml からマッピング ドキュメントを解析できませんでした

注: 例外の完全なスタック トレースとその根本原因は、GlassFish Server Open Source Edition 3.1.2.2 ログで入手できます。GlassFish サーバー オープン ソース版 3.1.2.2

<%-- 
    Document   : index
    Created on : Sep 24, 2013, 10:26:57 AM
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Register</title>
    </head>
    <center>
    <body>
        <h1>ENTER DETAILS HERE</h1>
    <s:form action="abc">
        <s:textfield name="roll" label="Roll No."/></br>
        <s:textfield name="name" label="Name"/></br>
        <s:textfield name="course" label="Course"/></br>
        <s:submit label="Click here to save"></s:submit>
    </s:form>
    </body>
    </center>
</html>

<%-- 
    Document   : welcome
    Created on : Sep 24, 2013, 11:02:18 AM
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Details</title>
    </head>
    <center>
        <body>
            <h1>Your details are saved now</h1>
            Roll No.: <s:property value="roll"/></br>
            Name: <s:property value="name"/></br>
            Course: <s:property value="course"/></br>
        </body>
    </center>
</html>

    <?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>
            <property name="hibernate.hbm2ddl.auto">update</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbms</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.connection.password"></property>
            <mapping resource="user.hbm.xml"/>
        </session-factory>
    </hibernate-configuration>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="tanuj.Register" table="student">
  <id name="id">
      <generator class="increment"></generator>
  </id>
  <property name="roll" type="integer" column="roll"></property>
  <property name="name" type="string" column="name"></property>
  <property name="course" type="string" column="course"></property>
  </class>
</hibernate-mapping>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <!-- Configuration for the default package. -->
    <package name="default" extends="struts-default">
        <action name="abc" class="tanuj.Register">
            <result name="success">welcome.jsp</result>
        </action>
    </package>
</struts>


package tanuj;

import com.opensymphony.xwork2.ActionSupport;

/**
 *
 * @author Administrator
 */
public class Register extends ActionSupport {

    private int roll;
    private String name, course;

    public int getRoll() {
        return roll;
    }

    public void setRoll(int roll) {
        this.roll = roll;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCourse() {
        return course;
    }

    public void setCourse(String course) {
        this.course = course;
    }



    public String execute() {
        RegisterSaveHiber.saveUser(this);
        return "success";
    }
}


package tanuj;

import org.hibernate.Session;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author Administrator
 */
public class RegisterSaveHiber {

    public static int saveUser(Register u) {
        Session session = new Configuration().configure("/hibernate.cfg.xml").
                buildSessionFactory().openSession();

        Transaction t = session.beginTransaction();
        int i = (Integer) session.save(u);

        t.commit();
        session.close();

        return i;
    }
}
4

0 に答える 0