为什么我收到HTTP状态500 - 未知实体:org.hibernate.impl.SessionImpl异常?

时间:2015-02-28 11:17:13

标签: java hibernate servlets

在尝试运行名为InsertHeader的servlet时,我遇到以下异常:

HTTP Status 500 - Unknown entity: org.hibernate.impl.SessionImpl

    type Exception report

    message Unknown entity: org.hibernate.impl.SessionImpl

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

    exception

    org.hibernate.MappingException: Unknown entity: org.hibernate.impl.SessionImpl
        org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
        org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
        org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
        org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
        org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
        org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
        org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
        org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
        org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
        org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
        org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
        servlet.InsertHeader.doGet(InsertHeader.java:42)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

的Servlet

        public class InsertHeader extends HttpServlet {

        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            int playerNumber = Integer.parseInt(request.getParameter("playernumber_header"));
            int woodWork = Integer.parseInt(request.getParameter("hitwoodwork"));
            int keeperTouch = Integer.parseInt(request.getParameter("keepertouch"));

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

            Header header = new Header();
            header.setHitWoodwork(woodWork);
            header.setKeeperTouch(keeperTouch);
            header.setPlayerNumber(playerNumber);

            sess.save(sess); // LINE THAT THROWS ERROR
            trans.commit();
        }
    }

header.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.Header" table="header">
           <id column='id' name='id' type="integer">
              <generator class="increment" />
          </id>

          <property column="hitwoodwork" name="hitWoodwork" type="integer"/>
          <property column="keepertouch" name="keeperTouch" type="integer"/>
          <property column="playernumber" name="playerNumber" type="integer"/>
      </class>
    </hibernate-mapping>

这可能是什么原因?抛出异常的servlet的URL是:

http://localhost:8081/Football/InsertHeader?playernumber_header=12&keepertouch=1&hitwoodwork=0

1 个答案:

答案 0 :(得分:1)

您尝试保存Session对象。

变化:

sess.save(sess); 

要:

sess.save(header);