forked from NeilAlishev/SpringCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
31 lines (24 loc) · 818 Bytes
/
App.java
File metadata and controls
31 lines (24 loc) · 818 Bytes
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
package org.example;
import org.example.model.Person;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* Hello world!
*/
public class App {
public static void main(String[] args) {
Configuration configuration = new Configuration().addAnnotatedClass(Person.class);
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
try {
session.beginTransaction();
Person person = session.get(Person.class, 1);
System.out.println(person.getName());
System.out.println(person.getAge());
session.getTransaction().commit();
} finally {
sessionFactory.close();
}
}
}