forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySession.java
More file actions
35 lines (30 loc) · 932 Bytes
/
MySession.java
File metadata and controls
35 lines (30 loc) · 932 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
32
33
34
35
package com.core;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
import java.util.List;
import org.hibernate.SQLQuery;
import com.actionForm.GetUseForm;
import org.hibernate.Query;
public class MySession {
static SessionFactory sessionFactory;
static {
try {
Configuration config = new Configuration().configure();
sessionFactory = config.buildSessionFactory();
} catch (Exception e) {
System.out.println("创建SessionFactory时的错误信息:" + e.getMessage());
}
}
//打开Session
public static Session openSession() {
Session session = sessionFactory.openSession();
return session;
}
//关闭Session
public static void closeSession(Session session) {
if (session != null) {
session.close();
}
}
}