Bom dia. Estou com esse problema no mapeamento do meu banco.
Seguem os códigos
Hibernate.cfg.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>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/aluno</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">root</property>
<mapping resource="aluno/aluno.hbm.xml"/>
</session-factory>
</hibernate-configuration>
aluno.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!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.Aluno" table="aluno"/>
<id name="alu_id" column="alu_id" type="int"/>
<property name="alu_nome" column="alu_nome"/>
<property name="alu_curso" column="alu_cusro"/>
</class>
</hibernate-mapping>
GravaAluno
package aluno;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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().buildSessionFactory();
Session sessao = fabrica.openSession();
Aluno aluno = new Aluno();
aluno.setAlu_id(null);
aluno.setAlu_curso("Sistemas de Informação");
Transaction tx_aluno = sessao.beginTransaction();
sessao.save(aluno);
tx_aluno.commit();
sessao.close();
}catch(Exception erro){
JOptionPane.showMessageDialog(null,"Erro na Inserçao: " +erro);
}
}
}
Erros:
run:
07/05/2011 11:03:12 org.hibernate.cfg.Environment
INFO: Hibernate 3.2.5
07/05/2011 11:03:12 org.hibernate.cfg.Environment
INFO: hibernate.properties not found
07/05/2011 11:03:12 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
07/05/2011 11:03:12 org.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
07/05/2011 11:03:12 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
07/05/2011 11:03:12 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
07/05/2011 11:03:12 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : aluno/aluno.hbm.xml
07/05/2011 11:03:12 org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(5) The content of element type “class” is incomplete, it must match “(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array),((join,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)”.
07/05/2011 11:03:12 org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(9) The element type “hibernate-mapping” must be terminated by the matching end-tag “”.
E ai pessoal alguma idéia do que seja?
Abraço