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》 学完框架基础知识后的烦恼!!!100分 jsp与asp间的数据加密传递 求够jsp分页.要源代码... 不能用自己的打包类? jsp怎样调用webservice,给出方法 我装了个apache+Resin3+jdk1.42运行JSP过一段时间后经常会造成cpu100%?( 在www.abc.com上,需取出abc.com应该写什么? 初學者問題多多 在用户注册例子中,想把一些已存入数据库的用户删除,可是删除不了,我遇到了麻烦,请支援!!! 怎样判断sql语言里有非法的字符集输入?? 急..急.. 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。