-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHibernateUtil.java
More file actions
43 lines (37 loc) · 1.23 KB
/
HibernateUtil.java
File metadata and controls
43 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* 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 utilidades;
import entidades.Usuario;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
// private static final SessionFactory sessionFactory;
// static {
// try {
// sessionFactory = new AnnotationConfiguration()
// .configure().buildSessionFactory();
// } catch (Throwable ex) {
// // Log exception!
// throw new ExceptionInInitializerError(ex);
// }
// }
//
// public static Session getSession()
// throws HibernateException {
// return sessionFactory.openSession();
// }
private static SessionFactory factory;
static {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure();
cfg.addAnnotatedClass(Usuario.class);
factory = cfg.buildSessionFactory();
}
public static Session getSession() {
return factory.openSession();
}
}