使用
getCurrentSession需要在 hibernate.cfg.xml 中添加的配置
- <property name="hibernate.current_session_context_class">thread</property>
创建类
HibernateUtil.java
实现单例模式的SessionFactor
使用getCurrentSession()获得session
- Session session = factory.getCurrentSession();