簡體   English   中英

配置休眠配置文件

[英]configure hibernate configuration file

以下是我的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 線程“主” 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

我是休眠的新手。 正在遵循教程。 得到這個錯誤。 有人可以幫我嗎?

您需要添加:

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

在xml文件的開頭。

編輯:(更新代碼后)

  1. 檢查<?xml ?>之前是否有空白或其他內容
  2. 檢查<?xml ?>之前是否有字節順序標記(BOM)( 這里是刪除它的教程)
  3. 檢查文檔中是否還有另一個<?xml ?>定義

如果任何人得到此,則不允許匹配“ [xX] [mM] [lL]”的處理指令目標。 錯誤

解決此錯誤的方法是 1.此行應該是第一行,並且在此行之前不能留任何空格。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM