Olá pessoal!
Estou estudando hibernate com java, não estou conseguindo solucionar o erro informado pelo java.
Abaixo o arquivo hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!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/hibernate</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">2344524246</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping resource="modelo/aluno.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Abaixo o arquivo 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" table="alunos">
<id name="aluCod" column="alucod" type="integer">
<generator class="sequence"></generator>
</id>
<property name="aluNome" column="alunome" type="string"></property>
<property name="aluCidade" column="alucidade" type="string"></property>
<property name="aluFone" column="alufone" type="string"></property>
<property name="aluCurso" column="alucurso" type="string"></property>
</class>
</hibernate-mapping>
Abaixo a classe de teste:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package modelo;
import javax.swing.JOptionPane;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
/**
*
* @author Jairo
*/
public class GravaAluno {
public static void main(String args[]){
try{
SessionFactory fabrica = new Configuration().configure("configuracao/hibernate.cfg.xml").buildSessionFactory();
Session sessao = fabrica.openSession();
Aluno aluno = new Aluno();
aluno.setAluNome("Jairo");
aluno.setAluCidade("Teresina");
aluno.setAluFone("86-32146219");
aluno.setAluCurso("Java Hibernate");
Transaction trAluno = sessao.beginTransaction();
sessao.save(aluno);
trAluno.commit();
sessao.close();
}catch(Exception erro){
JOptionPane.showMessageDialog(null, "Erro na inserção: "+erro);
}
}
}
OBSERVAÇÃO: ALUNO.HBM.XML ESTÁ NO MESMO PACOTE DA CLASSE GRAVAALUNO E O ARQUIVO HIBERNATE.CFG,XML ESTÁ EM OUTRO PACOTE