-
Notifications
You must be signed in to change notification settings - Fork 391
/
Copy pathMySessionFactory.java
34 lines (29 loc) · 1.17 KB
/
MySessionFactory.java
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
package com.game.repository;
import com.game.entity.Player;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import java.util.Properties;
public class MySessionFactory {
private static MySessionFactory instance;
private final SessionFactory sessionFactory;
public MySessionFactory(){
Properties properties = new Properties();
properties.put(Environment.DRIVER, "com.p6spy.engine.spy.P6SpyDriver");
properties.put(Environment.URL, "jdbc:p6spy:mysql://localhost:3306/rpg");
properties.put(Environment.DIALECT, "org.hibernate.dialect.MySQL8Dialect");
properties.put(Environment.USER, "root");
properties.put(Environment.PASS, "aSd123Rtu");
properties.put(Environment.HBM2DDL_AUTO, "update");
sessionFactory = new Configuration()
.addAnnotatedClass(Player.class)
.setProperties(properties)
.buildSessionFactory();
}
public static SessionFactory getSessionFactory() {
if (instance == null) {
instance = new MySessionFactory();
}
return instance.sessionFactory;
}
}