Elaborei as seguintes Classes:
[code]import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory SessionFactory = buildSessionFactory();
private static org.hibernate.SessionFactory buildSessionFactory() {
try {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure("hibernate.cfg.xml");
return cfg.buildSessionFactory();
} catch (Throwable e) {
System.out
.println("Criação inicial de objeto SessionFactory falhou. Erro: "
+ e);
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory(){
return SessionFactory;
}
}[/code]
[code]import org.hibernate.Session;
public class ConectaHibernateMySQL {
public static void main(String[] args) {
Session sessao = null;
try {
sessao = HibernateUtil.getSessionFactory().openSession();
System.out.println("Conectou!");
} finally {
sessao.close();
}
}
}[/code]
Com a seguinte XML:
[code]<?xml version="1.0" encoding="UTF-8"?>
org.hibernate.dialect.MySQLDialect com.mysql.jdbc.Driver jdbc:mysql://localhost/agenda root root thread5
20
300
50
3000
true
true
true
true
<mapping resource="com/livro/capitulo3/crudxml/Contato.hbm.xml"/>
<mapping class="com.livro.capitulo3.crudannotations.ContatoAnnotations"/>
[/code]
No entanto, não estou conseguindo compilar com o resultado: Conectou!
No Console o resultado é esse:
40 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.2-Final
70 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.2-Final
70 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
80 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
90 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
342 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
352 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: hibernate.cfg.xml
352 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: hibernate.cfg.xml
Criação inicial de objeto SessionFactory falhou. Erro: org.hibernate.HibernateException: hibernate.cfg.xml not found
Exception in thread "main" java.lang.NullPointerException
at com.livro.capitulo3.conexao.ConectaHibernateMySQL.main(ConectaHibernateMySQL.java:13)
[color=red]O que pode ser?[/color]