代码 是在spring+hibernate框架下
获取session
方法:
protected SessionFactory sessionFactory;
...
Session session = this.sessionFactory.getCurrentSession();
通过调用SessionFactory的getCurrentSession()方法
出现的异常:
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
解决:
配置文件中必须配置hibernate.current_session_context_class选项为thread:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource"