获取:HTTP状态500 - 无法确定类型:整数:可能是什么原因?

时间:2015-02-28 09:02:48

标签: java mysql sql hibernate servlets

在尝试运行servlet InsertDribble时,我遇到了异常:

   HTTP Status 500 - Could not determine type for: Integer,
     for columns: [org.hibernate.mapping.Column(playernumber)]

    type Exception report

    message Could not determine type for: Integer, for columns: [org.hibernate.mapping.Column(playernumber)]

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    org.hibernate.MappingException: Could not determine type for: Integer, for columns: [org.hibernate.mapping.Column(playernumber)]
        org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
        org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
        org.hibernate.mapping.Property.isValid(Property.java:185)
        org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
        org.hibernate.mapping.RootClass.validate(RootClass.java:192)
        org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
        org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
        servlet.InsertDribble.doGet(InsertDribble.java:33)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.34 logs.

    Apache Tomcat/7.0.34

我不知道它的原因。

Servlet:

/*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package servlet;

    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;
    import pojo.Dribbles;

    /**
     *
     * @author user
     */
    public class InsertDribble extends HttpServlet {

        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    //        int playerNumber = Integer.parseInt(request.getParameter("playernumber"));
    //        int succesful = Integer.parseInt(request.getParameter("successful"));
    //        int unsuccessful = Integer.parseInt(request.getParameter("unsuccssful"));

            Configuration configuration = new Configuration().configure();
            SessionFactory sessFact = configuration.buildSessionFactory();
            Session sess = sessFact.openSession();
            Transaction trans = sess.beginTransaction();

            int playerNumber = 1;
            int succesful = 1;
            int unsuccessful = 1;
            Dribbles dr = new Dribbles();
            dr.setPlayerNumber(playerNumber);
            dr.setSuccessful(succesful);
            dr.setUnsuccessful(unsuccessful);

            sess.save(dr);
            trans.commit();
        }
    }

dribble.hbm.xml:

<?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="pojo.Dribbles" table="dribbles">
           <id column='id' name='id'>
              <generator class="increment" />
          </id>

          <property column="playernumber" name="playerNumber" type="integer"/>
          <property column="successful" name="successful" type="integer"/>
          <property column="unsuccessful" name="unsuccessful" type="integer"/>
      </class>
    </hibernate-mapping>

POJO:

/*
         * To change this template, choose Tools | Templates
         * and open the template in the editor.
         */
        package pojo;

        /**
         *
         * @author user
         */
        public class Dribbles {
            private int playerNumber,successful,unsuccessful,id;

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public int getPlayerNumber() {
                return playerNumber;
            }

            public void setPlayerNumber(int playerNumber) {
                this.playerNumber = playerNumber;
            }

            public int getSuccessful() {
                return successful;
            }

            public void setSuccessful(int successful) {
                this.successful = successful;
            }

            public int getUnsuccessful() {
                return unsuccessful;
            }

            public void setUnsuccessful(int unsuccessful) {
                this.unsuccessful = unsuccessful;
            }


        }

表的SQL查询:

CREATE TABLE dribbles(id INT,playernumber INT,successful INT,unsuccessful INT,PRIMARY KEY(id));

1 个答案:

答案 0 :(得分:0)

您可以尝试将dribble.hbm.xml文件更改为以下内容:

<?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="pojo.Dribbles" table="dribbles">
       <!-- include a type for the id primary key column -->
       <id column='id' name='id' type="integer">
          <generator class="increment" />
      </id>

      <property column="playernumber" name="playerNumber" type="integer"/>
      <property column="successful" name="successful" type="integer"/>
      <property column="unsuccessful" name="unsuccessful" type="integer"/>
  </class>
</hibernate-mapping>

您得到的错误具有误导性。首先,堆栈跟踪显示HTTP Status 500,这是一般服务器错误,不会告诉您内部情况。然后堆栈跟踪抱怨映射表列playernumber。但我认为Hibernate正在InsertDribble.java的第33行上滚动,因为它是你使用它的第一个地方。