Hibernate读不到配置文件 Unable to read XML hibernatejarxmlexception 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有dom4j.jar包。hibernate读取配置文件是基于dom4j的。 Java Project项目里没有webroot,而Web Project项目里是有webroot的,而且如果你web.xml没有配置的话一般默认的会去webroot下面找xml文件;好好找找看看你的xml文件存放的路径在Web Project项目中是否能被加载到 是不是没加载到呀?Element type "hibernate-mapping" must be declared.hibernate-mapping必须被初始化。 1.根据错误提示: at com.daocao.util.db.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)到这个地方看一下错误在哪里2.dom4j.jar包没有导入 虽说可能是这个问题你。但是现在工程虽然不一样,但是执行的都是单纯的.java,没有用到web 现在问题就是 Unable to read XML昨天还遇了个奇葩问题,看对象赋值和debug中堆栈里的值不一样....这就是一个单纯的new对象,没有用到其他东西,快崩溃了....如图: 看一下你的web.xml和struts.xml,很多时候都是因为这两个文件没配置好而导致找不到信息的。 hibernate的配置在哪里。new Configuration();就需要有SessionFactory的配置了。你没配置的话就户会报这个问题了 这个类是Hibernate文档中自带的一个帮助类,可以单例生成SessionFactory,写的比较好。类没有错误,估计是哪里配置的问题。 有没有导入dom4j.jar包啊?把你的配置文件贴出来看看 dom4j肯定导入了...导入包的图:hibernate.cfg.xml文件内容:<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory> <!-- Database connection settings --> <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> <property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=bbs</property> <property name="connection.username">sa</property> <property name="connection.password">sa</property> <!-- JDBC connection pool (use the built-in) --> <!-- <property name="connection.pool_size">1</property> --> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property> <!-- Enable Hibernate's automatic session context management --> <!-- <property name="current_session_context_class">thread</property> --> <!-- Disable the second-level cache --> <property name="cache.provider_class"> org.hibernate.cache.NoCacheProvider </property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <property name="myeclipse.connection.profile"> net.sourceforge.jtds.jdbc.Driver </property> <mapping resource="edu/a/Student.hbm.xml" /> <mapping class="edu.a.Teacher" /></session-factory></hibernate-configuration> 问题再说一下:现在虽然项目不一样,一个普通的Java Project,一个Web Project。但是用的都只是普通的类,没有使用web。 创建HIbernate工程时《Hibernate Specification:选择Hibernate 3.3 ,选择4.1会报Unable to read XML》 急求高手有关web开发的问题 请教一个常用的功能,怎样在操作完成后回到提交申请的页面? jsf 弱问高分入门问题 关于数据库表单输出的问题 JSP中的上传问题 求教高手,以.开头的文件如何加入到VSS里?? 怎么用spring发邮件? 寻求最简单的 ASP 和 JSP 单点登陆实现方案! 高分求助---jsp和mysql连接的详细介绍啊! 请各位同学帮我看看我的程序给出的错误!谢谢! (JSP在Tomcat4.0下) CSDN不玩啦,送分 怎么配置JSP服务器?
是不是没加载到呀?
Element type "hibernate-mapping" must be declared.
hibernate-mapping必须被初始化。
但是现在工程虽然不一样,但是执行的都是单纯的.java,没有用到web
这就是一个单纯的new对象,没有用到其他东西,快崩溃了....
如图:
这个类是Hibernate文档中自带的一个帮助类,可以单例生成SessionFactory,写的比较好。
类没有错误,估计是哪里配置的问题。
dom4j肯定导入了...
导入包的图:
hibernate.cfg.xml文件内容:<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=bbs</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>
<!-- JDBC connection pool (use the built-in) -->
<!--
<property name="connection.pool_size">1</property>
-->
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
<!-- Enable Hibernate's automatic session context management -->
<!--
<property name="current_session_context_class">thread</property>
-->
<!-- Disable the second-level cache -->
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property>
<property name="myeclipse.connection.profile">
net.sourceforge.jtds.jdbc.Driver
</property>
<mapping resource="edu/a/Student.hbm.xml" />
<mapping class="edu.a.Teacher" />
</session-factory>
</hibernate-configuration>
但是用的都只是普通的类,没有使用web。