Hibernate的存储都是在session中进行的,此session非彼session
下面就是从生成的Hibernate配置文件获得连接数据库,然后再得到session等等
package com.attence.tools; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateSessionFactory { private static Configuration configuration; private static SessionFactory sessionFactory; private static final String HIBERNATE_CONFIG = "hibernate.cfg.xml"; static { configuration = new Configuration().configure(HIBERNATE_CONFIG); sessionFactory = configuration.buildSessionFactory(); } public static Session getSession() { return sessionFactory.openSession(); } }
蜗牛—Hibernate之自写固定组件,布布扣,bubuko.com
原文:http://blog.csdn.net/qq1791422018/article/details/38691123