Error: Could not parse configuration: hibernate.cfg.xml

3

I am developing a Java Web application using Hibernate to persist the data in MySQL. At the time of testing hibernate for class main, the following error is displayed on the console:

jul 18, 2018 4:12:44 PM 
org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
jul 18, 2018 4:12:44 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.1.Final}
jul 18, 2018 4:12:44 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
jul 18, 2018 4:12:44 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
jul 18, 2018 4:12:44 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
jul 18, 2018 4:12:44 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate.cfg.xml
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2163)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:201)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:46)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:183)
at br.com.geovane.modelo.TestandoHibernate.GerarTabelas(TestandoHibernate.java:15)
at br.com.geovane.modelo.TestandoHibernate.main(TestandoHibernate.java:9)
Caused by: org.dom4j.DocumentException: Error on line 4 of document  : O 
destino da instrução de processamento correspondente "[xX][mM][lL]" não é 
permitido. Nested exception: O destino da instrução de processamento 
correspondente "[xX][mM][lL]" não é permitido.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2155)
... 6 more

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

    

    <mapping class="br.com.geovane.controle.Pessoa" />
    <mapping class="br.com.geovane.controle.PF" />
    <mapping class="br.com.geovane.controle.PJ" />

    <mapping class="br.com.geovane.controle.DocReceita" />
    <mapping class="br.com.geovane.controle.CPF" />
    <mapping class="br.com.geovane.controle.CNPJ" />

    <mapping class="br.com.geovane.controle.Telefone" />
    <mapping class="br.com.geovane.controle.Endereco" />

    <mapping class="br.com.geovane.controle.Animal" />
    <mapping class="br.com.geovane.controle.Cachorro" />
    <mapping class="br.com.geovane.controle.Gato" />

    <mapping class="br.com.geovane.controle.Servico" />
    <mapping class="br.com.geovane.controle.Banho" />
    <mapping class="br.com.geovane.controle.Consulta" />
    <mapping class="br.com.geovane.controle.Tosa" />
    <mapping class="br.com.geovane.controle.Vacina" />


    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/estimacao</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"></property>

    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>
    <property name="hibernate.pool_size">10</property>
    <property name="hibernate.hbm2dll.auto">create</property>

</session-factory>

Class ConnectionHibernate.java

static {
    try {
        sessionFactory = new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
    } catch (Throwable e) {
        System.err.println("\n\n\n ----------- Erro na fábrica de sessões Hibernate ---------------- \n\n\n");
        e.printStackTrace();
        System.err.println("\n\n\n ----------- Fim dos erros na fábrica de sessões Hibernate ------- \n\n\n");
        throw new ExceptionInInitializerError(e);
    }

}

//Retorna uma sessão de comunicação com o Banco de Dados
public static Session getInstance() {
    Session session = (Session) threadLocal.get();
    session = sessionFactory.openSession();
    threadLocal.set(session);
    return session;
}

Calling in the main class:

public static void main(String[] args) {
    GerarTabelas();
}

private static void GerarTabelas() {
    AnnotationConfiguration cfg = new AnnotationConfiguration();

    cfg.configure("hibernate.cfg.xml");
    SchemaExport sx = new SchemaExport(cfg);
    sx.create(true, true);
}

I researched this problem, but I could not resolve it. If you can help, I'll be grateful!

    
asked by anonymous 18.07.2018 / 20:53

1 answer

0

For my projects I'm using this dialect:

  org.hibernate.dialect.MySQL5InnoDBDialect

Maybe this information might help you:

Change this:

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

By this:

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    
18.07.2018 / 21:41