您的位置:首页 > 大数据 > 人工智能

Could not obtain transaction-synchronized Session for current thread

2016-11-14 22:21 351 查看
(hibernate4)

已经在web.xml中已经使用

<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

但是任然报错,后来----->

在application.xml

   <!-- 扫描业务逻辑层和模型层 -->

        <context:component-scan base-package="com.dao"/>

        <context:component-scan base-package="com.service"/>

        <context:component-scan base-package="com.action"/>

        <context:component-scan base-package="com.serviceImpl"/>

        <context:component-scan base-package="com.daoImpl"/>

        <!-- 支持注解 -->

        <context:annotation-config/>

        

        <tx:annotation-driven transaction-manager="transactionManager"/>

在serviceImpl中的方法上添加

@Transactional
public void addSubject(Subject subject) {
save(subject);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hibernate session
相关文章推荐