不能用hbm.xml做bean文件的映射

时间:2014-04-01 13:27:34

标签: java hibernate

这些是由于映射而无法运行的代码文件

这是我的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>
    <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/kamal</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"/>
    <property name="hibernate.connection.pool_size">500</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.show_sql">true</property>
    <mapping resource="aaa.hbm.xml"/> 
 </session-factory>
 </hibernate-configuration>

这是我的Aaa.hbm.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>
        <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/kamal</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"/>
        <property name="hibernate.connection.pool_size">500</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.show_sql">true</property>
        <mapping resource="aaa.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

我的服务器编码是 - :

package controller;

import bean.ssss;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Transaction;

public class example extends HttpServlet 
{
    protected void processRequest(HttpServletRequest request, HttpServletResponse   response)
        throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        controller.unique_connection.open_connection();
        try
        {
            String s1 = request.getParameter("names");
            String s2 = request.getParameter("roll");
            String s3 = request.getParameter("clas");
            String s4 = request.getParameter("email");
            String s5 = request.getParameter("img");
            Transaction trans=null;
            trans=controller.unique_connection.Listsession.beginTransaction();
            ssss im=new ssss();
            im.setClas(s3);
            im.setEmail(s4);
            im.setImg(s5);
            im.setNames(s1);
            im.setRoll(s2);
            controller.unique_connection.Listsession.save(im);
            trans.commit();
            response.sendRedirect("home.jsp");
        }
    }
}

查看代码是

<html>
<body> 
<table border="1" align="center">
<tr>
<th>Sr_no</th>
<th>Name</th>
<th>Roll_no</th>
<th>Class</th>
<th>Email</th>
<th>IMAGE</th>
</tr>
<%
    try
    {
        unique_connection uq=new unique_connection();
        uq.open_connection();
        controller.query qry = new query();
        List lst = qry.select("select sr_no,names,roll,clas,email,img from ssss");
        java.util.Iterator on = lst.iterator();
        while (on.hasNext())
        {
        Object oo[] = (Object[]) on.next();
        %>
            <tr>
                <td><%=oo[0].toString() %></td>
                <td><%=oo[1].toString() %></td>
                <td><%=oo[2].toString() %></td>
                <td><%=oo[3].toString() %></td>
                <td><%=oo[4].toString() %></td>
                <td><%=oo[5].toString() %></td>
            </tr>
        <%
        }
    }        
    catch(Exception ee)
    {
        out.print(ee.getMessage());
    }
    %>                        
</table>
</body>
</html>
运行此文件时会生成

映射问题,我不知道它为什么会出现。

0 个答案:

没有答案