Hibernate,将.hbm.xml文件添加到cfg.xml文件中

时间:2011-06-22 01:15:59

标签: hibernate jsp exception tomcat hbm

我需要一些信息

什么是hbm.xml文件???我只知道* .hbm文件

以及如何将.hbm.xml文件添加到cfg.xml文件???

我想知道,因为我在尝试运行我的jsp时遇到错误,他们说你必须将.hbm.xml文件添加到cfg.xml文件中!

这是错误:

exception 

org.apache.jasper.JasperException:javax.servlet.ServletException:net.sf.hibernate.MappingException:没有持久性:MyDB.student     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:531)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

导致mère

javax.servlet.ServletException:net.sf.hibernate.MappingException:没有持久性:MyDB.student     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:901)     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:830)     org.apache.jsp.JSP.index_jsp._jspService(index_jsp.java:103)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

导致mère

net.sf.hibernate.MappingException:没有针对:MyDB.student的持久性     net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:347)     net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2690)     net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2697)     net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:763)     net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)     org.apache.jsp.JSP.index_jsp._jspService(index_jsp.java:75)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

1 个答案:

答案 0 :(得分:2)

  1. hbm文件通常是XML,通常具有扩展名.hbm.xml。如果你将它们命名为.hbm,则会破坏惯例。

  2. 您不必从hibernate.cfg.xml全部映射它们 - 您可以通过编程方式或通过Spring进行映射。

  3. 如果您愿意,您只需添加类似于此

    的内容
        <mapping resource="org/hibernate/auction/Item.hbm.xml"/>
        <mapping resource="org/hibernate/auction/Bid.hbm.xml"/>