Estou desenvolvendo uma aplicação Java Web utilizando o Hibernate para persistir os dados no MySQL. No momento de realizar o teste da conexão com o hibernate pela class main, é exibido o seguinte erro no 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
Arquivo 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">
<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>
Classe ConexaoHibernate.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;
}
Chamada na classe principal:
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);
}
Pesquisei sobre esse problema, no entanto não consegui resolver. Se puderem ajudar, ficarei grato!