Hibernate 异常找不到持久化类的配置文件,郁闷!

问题描述

hibernate 配置文件如下:<?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="dialect">org.hibernate.dialect.SQLServerDialect</property><property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property><property name="hibernate.connection.url">jdbc:jtds:sqlserver://127.0.0.1:1433/</property><property name="hibernate.connection.username">sa</property><property name="hibernate.connection.password">sa</property><property name="hbm2ddl.auto">update</property><property name="show_sql">true</property><mapping resource="com/hgp/model/Revert.hbm.xml" /><mapping resource="com/hgp/model/user.hbm.xml" /> <mapping resource="com/hgp/model/Message.hbm.xml" /> </session-factory></hibernate-configuration>报错如下:2012-11-29 10:50:35 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() for servlet MessageServlet threw exceptionjava.lang.NullPointerExceptionat com.hgp.util.HibernateUtil.getSession(HibernateUtil.java:45)at com.hgp.dao.MessageDao.findPaging(MessageDao.java:122)at com.hgp.service.MessageServlet.doPost(MessageServlet.java:99)at com.hgp.service.MessageServlet.doGet(MessageServlet.java:44)at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706)at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:677)at org.apache.jsp.index_jsp._jspService(index_jsp.java:66)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)at java.lang.Thread.run(Thread.java:619)org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/hgp/model/Revert.hbm.xmlat org.hibernate.cfg.Configuration.addResource(Configuration.java:523)at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1511)at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)at com.hgp.util.HibernateUtil.rebuliderSessionFactory(HibernateUtil.java:80)at com.hgp.util.HibernateUtil.getSession(HibernateUtil.java:42)at com.hgp.dao.MessageDao.findPaging(MessageDao.java:122)at com.hgp.service.MessageServlet.doPost(MessageServlet.java:99)at com.hgp.service.MessageServlet.doGet(MessageServlet.java:44)at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706)at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:677)at org.apache.jsp.index_jsp._jspService(index_jsp.java:66)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)at java.lang.Thread.run(Thread.java:619)Caused by: org.hibernate.MappingException: invalid mappingat org.hibernate.cfg.Configuration.addInputStream(Configuration.java:463)at org.hibernate.cfg.Configuration.addResource(Configuration.java:520)... 40 moreCaused by: org.xml.sax.SAXParseException: Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)at org.dom4j.io.SAXReader.read(SAXReader.java:465)at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:460)... 41 more2012-11-29 10:50:35 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for servlet jsp threw exceptionjava.lang.NullPointerExceptionat com.hgp.util.HibernateUtil.getSession(HibernateUtil.java:45)at com.hgp.dao.MessageDao.findPaging(MessageDao.java:122)at com.hgp.service.MessageServlet.doPost(MessageServlet.java:99)at com.hgp.service.MessageServlet.doGet(MessageServlet.java:44)at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706)at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:677)at org.apache.jsp.index_jsp._jspService(index_jsp.java:66)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)at java.lang.Thread.run(Thread.java:619)

解决方案

Could not parse mapping document from resource com/hgp/model/Revert.hbm.xml Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".hbm配置文件仔细检查下,应该是格式或者写法上有错误,无法解析。

时间: 2024-09-28 16:21:29

Hibernate 异常找不到持久化类的配置文件,郁闷!的相关文章

Hibernate含List属性的持久化类的CRUD操作范例

1.hibernate.cfg.xml  代码如下 复制代码 <!DOCTYPE hibernate-configuration PUBLIC         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuratio

hibernate 根据持久化类 创建数据库表的时候出现的错误如下,请大神帮忙解决?

问题描述 hibernate 根据持久化类 创建数据库表的时候出现的错误如下,请大神帮忙解决? 十二月 09, 2015 1:49:52 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata 信息: table not found: DIC_TAB 十二月 09, 2015 1:49:52 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata 信息:

解析Java的Hibernate框架中的持久化类和映射文件_java

持久化类Hibernate的整个概念是采取从Java类属性的值,并将持久到数据库表.一个映射文件Hibernate的帮助确定如何从拉动类的值,并将它们映射与表和相关的域. 其对象或实例将存储在数据库表中的Java类在Hibernate中称为持久化类. Hibernate的效果最好,如果这些类遵循一些简单的规则,也称为普通Java对象(POJO)编程模型.有下列持久化类的主要规则,但是,这些规则并不是必需的. 将所有的持久化Java类需要一个默认的构造函数. 所有类应该包含为了让容易识别对象内Hi

Hibernate持久化类(Map)集合属性的Key为组件的映射

1.hibernate.cfg.xml  代码如下 复制代码 <!DOCTYPE hibernate-configuration PUBLIC         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuratio

Java中Hibernate持久化类(map)集合属性的元素为组件的映射

1.hibernate.cfg.xml  代码如下 复制代码 <!DOCTYPE hibernate-configuration PUBLIC         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuratio

简介Java的Hibernate框架中的Session和持久化类_java

SessionSession对象用于获取与数据库的物理连接. Session对象是重量轻,设计了一个互动是需要与数据库每次被实例化.持久化对象被保存,并通过一个Session对象中检索. 会话中的对象不应该保持开放很长一段时间,因为他们通常不被线程安全的,他们应该被创建并根据需要摧毁他们.这次会议的主要功能是提供创建,读取和删除操作映射的实体类的实例.实例中可能存在以下三种状态之一在给定时间点: 短暂性: 持久化类的未与会话相关联,并在数据库中没有代表性,没有标识值的新实例被Hibernate认

在Hibernate框架中编写持久对象类实现外键关联的几点注意事项

关系数据库系统本身就比较复杂,加上Hibernate的O/R映射层,复杂度加重了,很容易出现问题,本人将最近遇到的问题和解决方法做一个总结,整理在下面的一系列文章中 正确理解Hibernate的聚合类型(collection)的使用 在Hibernate中正确实现关联关系中的级联操作(cascading) 在Hibernate框架中编写持久对象类实现外键关联的几点注意事项 本文是第三篇,讲解在one-to-many(一对多)关联关系中的对象类的几个关键方法的实现.主要是equals(),hash

shh项目错误-MyEclipse下生成持久化类,查询出错了

问题描述 MyEclipse下生成持久化类,查询出错了 java.lang.RuntimeException: org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select user0_.userID as col_0_0_, user0_.userName as col_1_0_, user0_.userPassword as col_2_0_ from

Myeclipse 自动生成可持久化类的映射文件的方法_Mysql

1.打开DB Browser,新建一个数据库的连接,找到想要持久化操作的数据库表的图标,右键选择hibernate reverse engineering 2.之后出现如下所示: java src folder:对应工程的src目录 java packega:对应工程中存放的包名,一般选择和持久化类放在一起 create pojo<>DB table mapping information:选上    create a hibernate mapping file(*.hbm.xml) for