-
Hibernate 异常找不到持久化类的配置文件,郁闷!5
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 exception
java.lang.NullPointerException
at 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.xml
at 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 mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:463)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:520)
... 40 more
Caused 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 more
2012-11-29 10:50:35 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at 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)
2012年11月29日 10:52
相关推荐
"Hibernate自动生成持久化类和映射文件"这个话题主要涉及如何利用myEclipse这款集成开发环境的反向工程功能,快速地根据数据库中的表结构生成对应的Hibernate配置文件、映射文件以及持久化类。下面将详细介绍这一...
《精通Hibernate:Java对象持久化详解》是一本深入解析Hibernate技术的专著,它主要针对Java开发者,旨在帮助他们理解和掌握Java对象持久化的精髓。Hibernate作为一款强大的对象关系映射(ORM)框架,极大地简化了...
3.4.2 把Customer持久化类映射到CUSTOMERS表 3.5 通过Hibernate API操纵数据库 3.5.1 Hibernate的初始化 3.5.2 访问Hibernate的Session接口 3.6 运行helloapp应用 3.6.1 创建运行本书范例的系统环境 ...
在Java世界中,Hibernate是一个非常流行的持久化框架,它简化了数据库操作,使得开发者可以更加专注于业务逻辑而不是底层的SQL语句。本知识点主要聚焦于Hibernate的配置文件,它是使用Hibernate进行数据库交互的基础...
2. **环境配置**:讲解如何配置Hibernate所需的环境,包括JDK、数据库、IDE等,以及编写基本的hibernate.cfg.xml配置文件。 3. **实体映射**:详述如何使用Hibernate的XML映射文件(hbm.xml)或注解来定义Java类与...
1. **配置文件(hibernate.cfg.xml)**: 这是Hibernate的主配置文件,用于设置数据库连接参数、缓存策略等。其中,最重要的配置是`<hibernate-configuration>`、`<session-factory>`和`<property>`标签。 2. **映射...
1. **实体映射**:定义实体类与数据库表之间的映射关系,通常通过XML配置文件或注解完成。映射信息包括表名、字段名、主键策略等。 2. **会话管理**:会话(Session)是Hibernate与数据库交互的基本单元。通过会话...
对象持久化是将应用程序中的对象状态存储到持久化介质(如数据库)的过程,使得即使程序关闭,对象的状态也能被保留下来。在Hibernate中,对象的生命周期包括瞬时态、托管态、持久态和脱管态。通过Hibernate,我们...
Hibernate作为一款强大的Java持久化框架,极大地简化了数据库操作,使得开发者可以更加专注于业务逻辑而非繁琐的SQL编写。本篇将深入探讨如何在Hibernate中调用配置文件中的SQL语句,以此提高代码的可维护性和灵活性...
### Hibernate 数据持久化组件 #### 一、背景与概述 在现代软件开发中,数据持久化是一项关键的技术,它解决了程序运行过程中数据的保存问题。根据题目提供的信息,“内存是暂时存储设备,断电后数据易丢失”,这...
在Java开发中,对象持久化是将程序中的对象状态存储到持久化存储(如数据库)中,并能在后续的运行时恢复这些状态的过程。Hibernate提供了一种优雅的方式来处理这个问题,通过将Java类与数据库表进行映射,使得Java...
本章主要介绍单个持久化类与单个数据库表之间进行映射的方法,尤其是当持久化类的属性不和数据库表的字段一一对应时的映射技巧。 5.1 持久化类的属性及访问方法 101 5.1.1 基本类型属性和包装类型属性 102 5.1.2 ...
1. **加载配置文件**:通过`Configuration`类加载`hibernate.cfg.xml`配置文件和其他相关的映射文件。 2. **创建SessionFactory**:根据配置信息创建SessionFactory实例。 3. **打开Session**:使用SessionFactory...
1. 创建SessionFactory:通过Configuration类加载hibernate.cfg.xml配置文件,然后调用configure()方法,最后buildSessionFactory()生成SessionFactory实例。 2. SessionFactory是线程不安全的,通常在应用启动时...
在开发Java应用程序,特别是涉及到持久化层操作时,Hibernate是一个常用的ORM(对象关系映射)框架。然而,由于各种依赖库的问题,可能会遇到多种异常。本文将深入探讨Hibernate常见的异常,以及与之相关的依赖库。 ...
1. hibernate.cfg.xml:这是Hibernate的核心配置文件,用于定义数据源、持久化类、SessionFactory等相关设置。例如,你需要在其中指定数据库连接的URL、用户名、密码,以及JDBC驱动等信息。例如: ```xml <hibernate...
5. Hibernate配置文件:一个典型的Hibernate配置文件名为hibernate.cfg.xml,它定义了数据库连接信息(如URL、用户名、密码)、持久化类、方言、缓存策略等。配置文件中的设置直接影响到Hibernate如何与数据库交互。...
本教程将深入讲解如何根据数据库表自动生成实体类、Hibernate配置文件以及实体映射文件。 首先,我们需要了解Hibernate的基本概念。Hibernate提供了一个在Java应用中使用的持久化模型,它允许开发者用面向对象的...