HibernateUtil

Tenho o seguinte código que é o HibernateUtil que peguei na net, porém ele utiliza o AnnotationConfiguration que já está obsoleto no hibernate4. Alguém sabe algo mais atualizado?

[code]import Model.Livro;
04
import org.hibernate.cfg.AnnotationConfiguration;
05
import org.hibernate.SessionFactory;
06

07
/**
08

  • Hibernate Utility class with a convenient method to get Session Factory object.
    09

10

  • @author José Alexandre
    11
    */
    12
    public class HibernateUtil {
    13

14
private static SessionFactory sessionFactory;
15

16
private HibernateUtil() {
17
}
18

19
public static SessionFactory getSessionFactory() {
20
if (sessionFactory == null) {
21
try {
22
// Create the SessionFactory from standard (hibernate.cfg.xml)
23
// config file.
24
AnnotationConfiguration ac = new AnnotationConfiguration();
25
ac.addAnnotatedClass(Livro.class);
26
sessionFactory = ac.configure().buildSessionFactory();
27
} catch (Throwable ex) {
28
// Log the exception.
29
System.err.println(“Initial SessionFactory creation failed.” + ex);
30
throw new ExceptionInInitializerError(ex);
31
}
32
return sessionFactory;
33
} else {
34
return sessionFactory;
35
}
36
}
[/code]

Deve ser usado o ServiceRegistry, recomendo que leia http://blog.caelum.com.br/as-novidades-do-hibernate-4/

Basta adaptar um pouquinho e você terá o que precisa aqui