0
votes

following is my hibernate.cfg.xml file

<?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>

Error I am getting is as follows

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /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

I am new to Hibernate. Was following a tutorial. Got this error. Can anybody help me with this??

2
from stack trace it seems Hibernate configuration xml has error..please do post configuration - Jayaram
Google for "The processing instruction target matching "[xX][mM][lL]" is not allowed", and you'll find the answer. - JB Nizet
Thanks JB. Followed your suggestion, googled it and found that a white space before <?xml version="1.0" encoding="utf-8"?> was causing the issue. - Eagle

2 Answers

1
votes

you need to add:

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

at the beginning of your xml file.

Edit:(after you updated your code)

  1. check if there are some blank space or other content before the <?xml ?>
  2. check if there is a Byte Order Mark (BOM) before the <?xml ?> (here is a tutorial to remove it)
  3. check if there is another <?xml ?> definition in your document
-2
votes

if any one get this The processing instruction target matching "[xX][mM][lL]" is not allowed. error

Solution to this error is that 1.This line should be the firs line and should not leave any space before this line.