首页 文章

配置hibernate配置文件

提问于
浏览
0

以下是我的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) Logger 实现
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的新手 . 正在关注一个教程 . 得到了这个错误 . 任何人都可以帮助我吗?

2 回答

  • 1

    你需要添加:

    <?xml version="1.0" encoding="utf-8"?>
    

    在xml文件的开头 .

    Edit: (更新代码后)

    • 检查 <?xml ?> 之前是否有空格或其他内容

    • 检查 <?xml ?> 之前是否有字节顺序标记(BOM)(here是删除它的教程)

    • 检查文档中是否有另一个 <?xml ?> 定义

  • -2

    如果有人得到这个 The processing instruction target matching "[xX][mM][lL]" is not allowed. 错误

    这个错误的解决方案是 **** 1.这条线应该是第一行,不应该在此行之前留下任何空格 .

相关问题