Olá pessoal ca estou novamente, estava configurando o hibernate para começar aprender, só que ai surgiu um erro que no meu ver está dizendo que ele não está achando o arquivo hibernate.cfg.xml que está na pasta C:\Users\matheus\workspaceJEE\TesteComHibernate\src antes de todos os pacotes
ai vão as classes:
package com.livro.conexao;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
public static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory(){
try {
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
return cfg.buildSessionFactory();
} catch (Throwable e) {
System.out.println("Criação do objeto sessionFactory falho" + e);
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
classe para teste:
package com.livro.conexao;
import org.hibernate.Session;
public class HibernatePostgre {
public static void main(String[]args){
Session sessao = null;
try{
sessao = HibernateUtil.getSessionFactory().openSession();
System.out.println("CONECTOU");
}finally{
sessao.close();
}
}
}
erro:
SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
16 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.2-Final
18 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
35 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
130 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: hibernate.cfg.xml
130 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: hibernate.cfg.xml
Criação do objeto sessionFactory falhoorg.hibernate.HibernateException: hibernate.cfg.xml not found
Exception in thread "main" java.lang.NullPointerException
at com.livro.conexao.HibernatePostgre.main(HibernatePostgre.java:14)
O problema era que mesmo tanto no diretório certo, ele tinha que estar pela IDE ou seja ele teria de parar la quando eu o jogasse na pasta src pela IDE.