ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 绑定 hibernate 提供了此方法,不用自己去手写了. 特点: 1. 默认关闭,需要配置开启 . ~~~ <property name="hibernate.current_session_context_class">thread</property> //开启,从当前线程中获取session ~~~ 2. 会自动关闭连接. ## 代码 ~~~ SessionFactory sessionFactory = Hibernate.getSessionFactory(); Session currentSession = sessionFactory.getCurrentSession(); Transaction tx = currentSession.beginTransaction(); //TODO tx.commit(); ~~~