以下是我的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">com.mysql.jdbc.driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect </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">create</property>
<!-- Names the annotated entity class -->
<mapping class="org.javabrains.koushik.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>
我得到的错误如下
SLF4J:无法加载“org.slf4j.impl.StaticLoggerBinder”类。
SLF4J:默认为无操作(NOP)记录器实现
SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder。
线程“main”中的异常org.hibernate.HibernateException:无法解析配置:/hibernate.cfg.xml
Stack Trace:
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at org.koushik.hibernate.HibernateTest.main(HibernateTest.java:13)
Caused by: org.dom4j.DocumentException: Error on line 1 of document : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 3 more
我是Hibernate的新手。正在关注一个教程。得到了这个错误。任何人都可以帮我这个吗?
答案 0 :(得分:1)
你需要添加:
<?xml version="1.0" encoding="utf-8"?>
在xml文件的开头。
修改(更新代码后)
<?xml ?>
<?xml ?>
之前是否有字节顺序标记(BOM)(here是删除它的教程)<?xml ?>
定义答案 1 :(得分:-2)
如果有人得到此 不允许匹配“[xX] [mM] [lL]”的处理指令目标。 错误
此错误的解决方案是 的 强> 这条线应该是第一条线,不应该在此线之前留下任何空间。