Leandro…Blz?
Olha só…eu to estudadndo esse material que vc me enviou, que por sinal é muito bom, só que tá dando um errinho no meu projeto…no primeiro exercicio que cria o metodo save().
Queria um help seu pra que eu consiga evoluir nesse passo…
Minhas classes e arquivos são:
HibernateUtil.java;
Cliente.java;
ClienteDAO;
Principal.java;
hibernate.cfg.xml;

segue abaixo as classes e o erro:
HibernateUtil.java
package teste;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Cliente.java;
package teste;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "cliente")
public class Cliente implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "nome_cliente", nullable = false, length=60)
private String nome;
@Column(name = "idade", nullable = false, length = 5)
private Long idade;
public Cliente(){
super();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Long getIdade() {
return idade;
}
public void setIdade(Long idade) {
this.idade = idade;
}
}
ClienteDAO;
[code]
package teste.dao;
import org.hibernate.Session;
import teste.Cliente;
import teste.HibernateUtil;
public class ClienteDAO {
private Session session;
public ClienteDAO(){
}
public void salvar(Cliente cli){
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(cli);
session.getTransaction().commit();
}
}[/code]
Principal.java
package teste;
import teste.dao.ClienteDAO;
public class Principal {
public static void main (String[] args){
Cliente c1 = new Cliente();
c1.setNome("Raul Seixas");
c1.setIdade(new Long(12));
Cliente c2 = new Cliente();
c2.setNome("Raul Seixas");
c2.setIdade(new Long(13));
ClienteDAO clienteDAO = new ClienteDAO();
clienteDAO.salvar(c1);
clienteDAO.salvar(c2);
}
}
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>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/teste</property>
<property name="connection.username">root</property>
<property name="connection.password">igor</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</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>
<mapping class="teste.Cliente"/>
</session-factory>
</hibernate-configuration>
erro no console do eclipse:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found