HibernateTools类

  [size=xx-large]import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateTools {
static SessionFactory sf = null;

static Session session = null;

public SessionFactory getSF() {
if (sf == null) {
Configuration cfg = new Configuration()
.configure("hibernate-cfg.xml");
sf = cfg.buildSessionFactory();
}
return sf;
}

public Session getSession() {
if (session == null) {
session = getSF().openSession();
}
return session;
}

public void close() {
if (session != null) {
session.close();
}
if (sf != null) {
sf.close();
}
}[size=xx-large]
}

你可能感兴趣的:(Hibernate,xml)