Problema - Duvida de iniciante

2 respostas
A

Estou quebrando a cabeca.
Ja procurei no forum e nao acho a solucao. Alguem saberia me dizer como arrumar isto?
Eu to assistindo as video aulas do prof. neri e ele conseguiu e eu nao... Estranho....

Este eh o erro:
run:
15 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
47 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
47 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
62 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
125 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: hibernate.cfg.xml
125 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: hibernate.cfg.xml
219 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: hibernate.cfg.xml(15) Document root element "hiberate-configuration", must match DOCTYPE root "hibernate-configuration".
234 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: hibernate.cfg.xml(15) Element type "hiberate-configuration" must be declared.
CONSTRUÍDO COM SUCESSO (tempo total: 5 segundos)

Configuracao do Hibernate

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">




org.gjt.mm.mysql.Driver


jdbc:mysql://javahibernate


root


123


org.hibernate.dialect.MySQLDialect




Mapeamento do aluno
<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : hibernate.cfg.xml
    Created on : 28 de Setembro de 2010, 21:35
    Author     : Anderson Luiz
    Description:
        Purpose of the document follows.
-->

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="Aluno" table="alunos">
        <id name="alu_codigo" colunm="alu_codigo" type="integer"/>
        <property name="alu_nome"/>
        <property name="alu_cidade"/>
        <property name="alu_fone"/>
        <property name="alu_curso"/>
    </class>
</hibernate-mapping>
Classe para gravar aluno
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Anderson Luiz
 */
import javax.swing.JOptionPane;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class GravaAluno {
    public static void main(String[] args){
        try{
            SessionFactory fabrica = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
            Session sessao = fabrica.openSession();
            Aluno aluno = new Aluno();
            aluno.setAlu_codigo(1);
            aluno.setAlu_nome("Anderson Luiz");
            aluno.setAlu_curso("Sistemas");
            aluno.setAlu_fone("4455-2511");
            aluno.setAlu_cidade("Santo andre");
            Transaction tx_aluno = sessao.beginTransaction();
            sessao.save(aluno);
            tx_aluno.commit();
            sessao.close();
        }catch(Exception erro){
            JOptionPane.showMessageDialog(null, "Erro na insercao: " + erro);
        }
    }
}

Estou anexando no post o print screen do erro

2 Respostas

LeandroRSilva

Não tenho certeza pois uso Hibernate com especificação JPA, mas não deveria ser ???

Veja o erro:

Até aqui o problema é só esse. Acho!

Guevara

Teste com este xml:

<!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="connection.url">jdbc:postgresql://localhost/meuprojeto</property>
		<property name="connection.driver_class">org.postgresql.Driver</property>
		<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>	
		<property name="connection.username">postgres</property>
		<property name="connection.password">123456</property>				
		<property name="connection.pool_size">1</property>
		<property name="current_session_context_class">thread</property>
		<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
		<property name="hibernate.show_sql">true</property>
		<property name="hibernate.format_sql">true</property>
		<property name="hibernate.hbm2ddl.auto">update</property>
		<mapping class="br.com.meuprojeto.bean.MinhaClasse"/>	
		<mapping class="br.com.meuprojeto.bean.MinhaOutraClasse"/>			
	</session-factory>
</hibernate-configuration>

Troque o que for do Postgre para MySQL.
[]s

Criado 28 de setembro de 2010
Ultima resposta 29 de set. de 2010
Respostas 2
Participantes 3