Hibernate 配置文件问题,一直报错不知什么原因?请高手解决一下
创建会话工厂失败org.hibernate.HibernateException:Couldnotparseconfiguration:/hibernate.cfg.xm...
创建会话工厂失败
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at com.mr.hibernate.HibernateInitialize.<clinit>(HibernateInitialize.java:19)
at com.mr.main.AddProduct.main(AddProduct.java:24)
Caused by: org.dom4j.DocumentException: Error on line 11 of document : The string "--" is not permitted within comments. Nested exception: The string "--" is not permitted within comments.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
... 3 more
创建会话工厂失败
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at com.mr.hibernate.HibernateInitialize.rebuildSessionFactory(HibernateInitialize.java:48)
at com.mr.hibernate.HibernateInitialize.getSession(HibernateInitialize.java:35)
at com.mr.main.AddProduct.main(AddProduct.java:24)
Caused by: org.dom4j.DocumentException: Error on line 11 of document : The string "--" is not permitted within comments. Nested exception: The string "--" is not permitted within comments.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
... 4 more
Exception in thread "main" java.lang.NullPointerException
at com.mr.main.AddProduct.main(AddProduct.java:29)
Hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <!-- 数据库驱动类 -->
<property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=db_database_product</property> <!-- 数据库连接的URL -->
<property name="connection.username">sa</property> <!-- 数据库连接的用户名 -->
<property name="connection.password">123456789</property> <!-- 数据库连接的密码>
<!-- SQL数据库方言SQLServer -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property> <!-- 打印SQL语句 -->
<!-- 映射文件 -->
<mapping resource="com/mr/product/Product.hbm.xml"/>
</session-factory>
</hibernate-configuration> 展开
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at com.mr.hibernate.HibernateInitialize.<clinit>(HibernateInitialize.java:19)
at com.mr.main.AddProduct.main(AddProduct.java:24)
Caused by: org.dom4j.DocumentException: Error on line 11 of document : The string "--" is not permitted within comments. Nested exception: The string "--" is not permitted within comments.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
... 3 more
创建会话工厂失败
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at com.mr.hibernate.HibernateInitialize.rebuildSessionFactory(HibernateInitialize.java:48)
at com.mr.hibernate.HibernateInitialize.getSession(HibernateInitialize.java:35)
at com.mr.main.AddProduct.main(AddProduct.java:24)
Caused by: org.dom4j.DocumentException: Error on line 11 of document : The string "--" is not permitted within comments. Nested exception: The string "--" is not permitted within comments.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
... 4 more
Exception in thread "main" java.lang.NullPointerException
at com.mr.main.AddProduct.main(AddProduct.java:29)
Hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <!-- 数据库驱动类 -->
<property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=db_database_product</property> <!-- 数据库连接的URL -->
<property name="connection.username">sa</property> <!-- 数据库连接的用户名 -->
<property name="connection.password">123456789</property> <!-- 数据库连接的密码>
<!-- SQL数据库方言SQLServer -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property> <!-- 打印SQL语句 -->
<!-- 映射文件 -->
<mapping resource="com/mr/product/Product.hbm.xml"/>
</session-factory>
</hibernate-configuration> 展开
2个回答
展开全部
你的hibernate.cfg.xml有错,
你注意一下<!-- 数据库连接的密码>这句,应该是<!-- 数据库连接的密码-->,少了两个--号
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <!-- 数据库驱动类 -->
<property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=db_database_product</property> <!-- 数据库连接的URL -->
<property name="connection.username">sa</property> <!-- 数据库连接的用户名 -->
<property name="connection.password">123456789</property> <!-- 数据库连接的密码-->
<!-- SQL数据库方言SQLServer -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property> <!-- 打印SQL语句 -->
<!-- 映射文件 -->
<mapping resource="com/mr/product/Product.hbm.xml"/>
</session-factory>
</hibernate-configuration>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询