[RESOLVIDO]MappingException: invalid configuration

1 resposta
wilsontads

Pessoal, estou tentando trabalhar com hibernate aqui, criei o schema do banco no mysql, e marquei nas configurações, pro hibernate criar as tabelas só que venho enfrentando esse probleminha acima.. criei uma classe pra mapear, apenas pra fazer alguns testes da seguinte forma:

CategoriaModel.java

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name="CategoriaModel")
public class CategoriaModel {
    
    @Id
    private int codigo;
    private int tipo;
    private int quantidadeMaxima;
    private Double valorHora;
    private Double valorDiaria;
    private Double valorMensalidade;
//...continua
e o meu arquivo de configuração da seguinte forma: hibernateconfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory name="">
  <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver
</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db
</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">nxsinter</property>
  <property name="hibernate.hbm2ddl.auto">create</property>
  <mapping class="br.com.estacdione.CategoriaModel"/>
  
 </session-factory>
</hibernate-configuration>
No entanto, tenho as seguintes msg de erro:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.hibernate.MappingException: invalid configuration
Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.

1 Resposta

wilsontads
Alterei o xml pra esse abaixo:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  
<hibernate-configuration>  
    <session-factory>  
     <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/db</property>  
        
        <property name="hibernate.connection.username">root</property>  
        <property name="hibernate.connection.password">nxsinter</property>  
        <!-- JDBC connection pool (use the built-in) -->  
        <property name="connection.pool_size">1</property>  
        <!-- SQL dialect   
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>-->  
        <!-- Enable Hibernate's automatic session context management -->  
        <property name="current_session_context_class">thread</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  
        tem que deixar essa propriedade ativa apos alguma modificação nas  
        tabelas ou no mapeamento, e depois comentar novamente, pois ela apaga  
        o que tem na tabela -->  
        <property name="hbm2ddl.auto">create</property>  
        <mapping class="br.com.estacione.model.CategoriaModel"/>                  
    </session-factory>  
</hibernate-configuration>
Criado 22 de fevereiro de 2012
Ultima resposta 22 de fev. de 2012
Respostas 1
Participantes 1